my issue is my partial view has a grid which has large data which takes time...now i want to use loading image like beforesend only to load my partial view...
my master data loaded quickly but my detail data in partial view takes time
here its my ajax ...
$.ajax({
url: '#Url.Action("get_Laptop_Detail_By_PO", "ChangeLaptopStage")',
data: { PO_Number: PO_Number },
beforeSend: function () {
$('.loader').show();
$('.main_area').addClass("disable_main_area");
},
success: function (data) {
var Qty = data.ItemQuantity
var Po_ID = data.PO_ID
$("#Total_laptop_Qty").val(Qty)
$("#PO_ID").val(Po_ID)
///This statement fetch my detail data in partial view ...i want to load this statement on loading image
$("#LaptopDetail").load('#(Url.Action("Laptop_detail_By_PO", "ChangeLaptopStage", null, Request.Url.Scheme))?PO_Number=' + PO_Number);
},
});
<div id="LaptopDetail">
</div>
This is my controller where partial view calls
[HttpGet]
public ActionResult Laptop_detail_By_PO(string PO_Number, ChangeLaptop_Stage REC)
{
Cls_Lot Lot_cls = new Cls_Lot();
List<LapTopDetail> LaptopDetail = new List<LapTopDetail>();
ds = new DataSet();
dt = new DataTable();
dt2 = new DataTable();
if (PO_Number != null)
{
ds = Lot_cls.getLaptopDetail_By_PO(22, PO_Number);
dt = ds.Tables[1];
foreach (DataRow drData in dt.Rows)
{
LaptopDetail.Add(new LapTopDetail
{
//RowNumber = Convert.ToInt32(drData["RowNumber"]),
PO_Dtl_ID = Convert.ToInt32(drData["ID"]),
PO_mstr_ID = Convert.ToInt32(drData["LapTop_Master_ID"]),
WareHouseStatus = drData["WareHouseStatus"].ToString(),
GulfITBarcode = drData["GulfITBarcode"].ToString(),
Item_Orgainal_srNO = drData["Item_Orgainal_srNO"].ToString(),
Category = drData["Category"].ToString(),
Make_Brand = drData["Make_Brand"].ToString(),
Series = drData["Series"].ToString(),
ModelNO = drData["ModelNO"].ToString(),
Color = drData["Color"].ToString(),
Processor_Brand = drData["Processor_Brand"].ToString(),
Processor_Type = drData["Processor_Type"].ToString(),
Processor = drData["Processor"].ToString(),
Speed_GHZ = drData["Speed_GHZ"].ToString(),
Memmory_MB = drData["Memmory_MB"].ToString(),
Memmory_Type = drData["Memmory_Type"].ToString(),
LCD_Screen_Size_inchs = drData["LCD_Screen_Size_inchs"].ToString(),
Touch_Screen = drData["Touch_Screen"].ToString(),
LCD_Teatures = drData["LCD_Teatures"].ToString(),
HDD_1_GB = drData["HDD_1_GB"].ToString(),
HDD_1_Type = drData["HDD_1_Type"].ToString(),
HDD_2_GB = drData["HDD_2_GB"].ToString(),
HDD_2_Type = drData["HDD_2_Type"].ToString(),
Graphic_Card_Name = drData["Graphic_Card_Name"].ToString(),
Graphic_Card_Memory_MB = drData["Graphic_Card_Memory_MB"].ToString(),
Camera = drData["Camera"].ToString(),
Camera_MegaPixel = drData["Camera_MegaPixel"].ToString(),
Lan = drData["Lan"].ToString(),
Wifi = drData["Wifi"].ToString(),
Bluetooth = drData["Bluetooth"].ToString(),
NFC = drData["NFC"].ToString(),
OpticalDriver = drData["OpticalDriver"].ToString(),
OpticalDriver_Type = drData["OpticalDriver_Type"].ToString(),
USB_Ports_Qty = drData["USB_Ports_Qty"].ToString(),
SD_Card_Reader = drData["SD_Card_Reader"].ToString(),
Stylus_Pen = drData["Stylus_Pen"].ToString(),
Finger_Printer_Reader = drData["Finger_Printer_Reader"].ToString(),
HDMI = drData["HDMI"].ToString(),
VGA = drData["VGA"].ToString(),
Display_Port = drData["Display_Port"].ToString(),
Thunderbolt = drData["Thunderbolt"].ToString(),
Audio_Port_Mic = drData["Audio_Port_Mic"].ToString(),
Audio_Port_Sound = drData["Audio_Port_Sound"].ToString(),
Speakers = drData["Speakers"].ToString(),
Battery = drData["Battery"].ToString(),
Ext_Adapter = drData["Ext_Adapter"].ToString(),
Other_1 = drData["Other_1"].ToString(),
Other_2 = drData["Other_2"].ToString(),
Other_3 = drData["Other_3"].ToString(),
Other_4 = drData["Other_4"].ToString(),
});
}
REC.Laptop_Detail = LaptopDetail;
return PartialView("Laptop_detail", REC);
}
else
{
return PartialView("P_Error");
}
}
Please help me
Use it on global $(document).ajaxStart and $(document).ajaxComplete events to attach it globally for all the request. There is an option called global in $.ajax which when set to false will not take global events into consideration.
$(document).ajaxStart(function(){
$('.loader').toggle();
$('.main_area').toggleClass("disable_main_area");
}).ajaxComplete(function(){
$('.loader').toggle();
$('.main_area').toggleClass("disable_main_area");
});
As I said this will attach it to all ajax request and if you want it not appear for all the ajax requests then add that global:false in each ajax request like on below:
$.ajax({
...
global:false,
...
});
For more global events visit - Global Events
Now if you want to attach it to only particular .load you can try as below:
$('.loader').show(); //show it before calling load
$("#LaptopDetail").load('#(Url.Action("Laptop_detail_By_PO", "ChangeLaptopStage", null, Request.Url.Scheme))?PO_Number=' + PO_Number), function() {
$('.loader').hide(); //hide once load completes
});
Related
I am facing a problem in rendering events from a SQL Server database. All events are getting fetched using this code but not getting displayed in my calendar, so can anyone please help me?
.cshtml code:
events: function(start, end, callback) {
debugger;
var startdate=start.format('DD-MM-YYYY HH:mm'),
enddate=end.format('DD-MM-YYYY HH:mm'),
params={'start_time':startdate,'end_time':enddate};
$.ajax({
type: 'GET',
url: '#Url.Action("GetAllEvents","Base")',
success: function (data) {
alert("hello");
}
});
}
,
my controller code:
public static List<Task_has_UsersModel> LoadAllTasks(double start, double end)
{
var fromDate = ConvertFromUnixTimestamp(start);
var toDate = ConvertFromUnixTimestamp(end);
var sql = "SELECT * from task_has_users";
var data = Database.Open("DefaultConnection").Query(sql);
List<Task_has_UsersModel> result = new List<Task_has_UsersModel>();
foreach (var item in data)
{
Task_has_UsersModel model = new Task_has_UsersModel();
model.Task_Id = Convert.ToInt32(item.Task_Id);
model.Project_Id = Convert.ToInt32(item.Project_Id);
model.start_time = item.start_time;
model.end_time = item.end_time;
result.Add(model);
}
return result;
}
[HttpPost]
public JsonResult GetAllEvents(double start, double end)
{
var ApptListForDate = LoadAllTasks(start,end);
var eventList = from e in ApptListForDate
select new
{
id=e.Task_Id,
name=e.Project_Id,
start=e.start_time.ToString(),
end=e.end_time.ToString(),
allDay=false,
color = "#008000",
//allDay=false,
className= "label-important" ,
};
var rows = eventList.ToArray();
return Json(rows, JsonRequestBehavior.AllowGet);
}
private static DateTime ConvertFromUnixTimestamp(double timestamp)
{
var origin = new DateTime(1970, 1, 1, 0, 0, 0, 0);
return origin.AddSeconds(timestamp);
}
}
I have tried with (double start,double end ) still my events are not getting displayed in calendar
Finally after 3 days of hard work , i have done this.... No need to write anything in events , just call a function , it will automatically appends the date range and all you are done................... thanks
.cshtml code:
events:'GetAllEvents',
eventLimit: 50,
editable: true,
droppable: true,
// timeFormat: 'hh:mm-h:mma ',
timeFormat: 'hh:mma ',
displayEventEnd : true,
my controller code:
public static List<Task_has_UsersModel> LoadAllTasks(string start, string end,string uname)
{
UsersContext db = new UsersContext();
var uid = (from i in db.UserProfiles
where i.UserName == uname
select i.UserId).FirstOrDefault();
int userId = Convert.ToInt32(uid);
// var culture = System.Globalization.CultureInfo.CurrentCulture;
var sql = "SELECT * from task_has_users where UserId = " + userId;
var data = Database.Open("DefaultConnection").Query(sql);
List<Task_has_UsersModel> result = new List<Task_has_UsersModel>();
foreach (var item in data)
{
Task_has_UsersModel model = new Task_has_UsersModel();
model.Task_Id = Convert.ToInt32(item.Task_Id);
model.Project_Id = Convert.ToInt32(item.ProjectId);
// model.start_time = Convert.ToDateTime(item.start_time);
model.start_time = (item.start_time).ToString("yyyy-MM-dd HH-mm-ss");
model.end_time = (item.end_time).ToString("yyyy-MM-dd HH-mm-ss");
model.title = item.title;
result.Add(model);
}
return result;
}
[HttpGet]
public JsonResult GetAllEvents(string start, string end)
{
string uname = (Session["UserName"]).ToString();
var ApptListForDate = LoadAllTasks(start,end,uname);
var eventList = from e in ApptListForDate
select new
{
id=e.Task_Id,
title=e.title,
start=e.start_time,
end=e.end_time,
allDay=false,
color = "#008000",
//allDay=false,
className= "label-important" ,
};
var rows = eventList.ToArray();
return Json(rows, JsonRequestBehavior.AllowGet);
}
finally done
How to execute controllers method on element shown.
I have a tabs, and i want load data when user open a tab, if i using ng-init, information loads after page loading.
var systemSettingsController = manageApp.controller("SystemSettingsController", [
"$scope", function($scope) {
$scope.tab = 1;
$scope.initTab = function(tab) {
$scope.tab = tab;
};
}
]);
var emailManagementController = manageApp.controller("EmailManagementController", function($scope, $http) {
$scope.smtpServer = "";
$scope.smtpLogin = "";
$scope.smtpPassword = "";
this.init = function() {
$http.get("/api/EmailSettings")
.then(function(res) {
var obj = angular.fromJson(res.data);
$scope.smtpServer = obj["Email.SmtpServer"];
$scope.smtpLogin = obj["Email.SenderAddress"];
$scope.smtpPassword = obj["Email.SenderPassword"];
});
};
...
I want execute method init (EmailManagementController) without using ng-init, and at the moment when this element is displayed on the screen, that is, its display will change to a property different from none.
try https://github.com/rpocklin/ui-router-tabs
basically you have each tabs (as view) associated with its controller.
$stateProvider.state('user', {
url: '',
controller: 'UserCtrl',
templateUrl: 'example.html'
}).state('user.settings', {
url: '/user/settings',
templateUrl: 'user/settings.html'
})
the controller initialize when the tab (view) active
Retrieve code from json.
C#code:-
var collection = getsortcat.Select(x => new
{
idterm = x.IDTerm,
mvo = x.MVO,
pic = x.Pic,
said = x.SAid,
termactive = x.TermActive,
vid = x.Vid,
fvo = x.FVO,
eterm = x.ETerm,
edef = x.EDef,
buse = x.BUse,
bterm = x.BTerm,
idcat = x.TermCat,
items = x.TermCategory1.IDCat,
catname = x.TermCategory1.TermCategory1
});
JavaScriptSerializer jss = new JavaScriptSerializer();
string output = jss.Serialize(collection);
return Json(output, JsonRequestBehavior.AllowGet);
Javascript Code:-
success: function (e) {
var txt = "'{ data :" + e + "}'";
var obj = eval("(" + txt + ")");
$('#pdata').append(obj.data[0]);
},
Not getting output. Please give me solution how to retrieve data from c# linq object to json to html?
First fix your controller action to get rid of any JavaScriptSerializers and manual plumbing code. Directly return the collection to the Json result:
var collection = getsortcat.Select(x => new
{
idterm = x.IDTerm,
mvo = x.MVO,
pic = x.Pic,
said = x.SAid,
termactive = x.TermActive,
vid = x.Vid,
fvo = x.FVO,
eterm = x.ETerm,
edef = x.EDef,
buse = x.BUse,
bterm = x.BTerm,
idcat = x.TermCat,
items = x.TermCategory1.IDCat,
catname = x.TermCategory1.TermCategory1
});
return Json(collection, JsonRequestBehavior.AllowGet);
Now inside the success callback the e parameter already represents an array of objects that were parsed. You don't need to call any eval. Directly access the elements (by index) and then the properties:
success: function (e) {
var txt = e[0].mvo;
},
you could also loop through the elements:
success: function (e) {
for (var i = 0; i < e.length; i++) {
var element = e[i];
alert(element.idterm);
}
},
Hello friends,
I am developing an app which displays category types using custom cell in tableview and then selects a row its go to detail which selected category type but I'm facing a problem that is I can't get row title in the next window. So please give me idea how to solve it.
Ti.include('PlacesTypeCustomCell.js');
var currentWindow = Titanium.UI.currentWindow;
var tableData = [];
// Create table
var tableData = new PlacesTypeCells();
var myTableView = Titanium.UI.createTableView
({
data:tableData,
top:45,
height:368
});
currentWindow.add(myTableView);
myTableView.addEventListener('click',function(e)
{
var index = e.index;
Ti.API.log('Row at index:'+index);
Titanium.App.Properties.setInt('index',index);
v//get each row title from tableview
var pageTitle = Titanium.App.Properties.setString('title',e.rowData.pageTitle);
Ti.API.log('Page Title:'+pageTitle);
var pageAddress = Titanium.App.Properties.setString('address',e.rowData.pageAddress);
Ti.API.log('Page Address:'+pageAddress);
var win = Titanium.UI.createWindow
({
url:'PlacesList.js',
title:'Place List'
});
Titanium.UI.currentTab.open(win,{animated:true});
});
//Custom Cell PlacesTypeCustomCell
var tableData=[];
var loader = Titanium.Network.createHTTPClient();
var url = "https://maps.googleapis.com/maps/api/place/search/json?";
url = url + "location=" + lat + ',' + lon;
url = url + "&radius=" + radius;
url = url + "&name=" + name;
url = url + "&sensor=" + sensor;
url = url + "&key=" + key;
Ti.API.info(url);
// Sets the HTTP request method, and the URL to get data from
loader.open("GET",url);
// Create our HTTP Client and name it "loader"
// Runs the function when the data is ready for us to process
loader.onload = function()
{
var obj = JSON.parse(this.responseText);
Ti.API.log(obj);
var results = obj.results;
Ti.API.log(results);
for (var i = 0; i < results.length; i++)
{
categoryName = obj.results[i].name;
reference = obj.results[i].reference;
Ti.API.log('Refernce:'+reference);
getDetailsData();
// Create a row and set its height to auto
row = Titanium.UI.createTableViewRow({height:'78'});
var placeImage = Titanium.UI.createImageView
({
image:'../iphone/appicon.png',
width:70,
height:50,
top:12,
left:5
});
// Create the label to hold the tweet message
var nameLabel = Titanium.UI.createLabel({
//text:name,
left:80,
top:5,
height:'auto',
width:200,
textAlign:'left',
font:{fontSize:12}
});
// Create the label to hold the tweet message
addressLabel = Titanium.UI.createLabel({
left:80,
top:25,
height:'auto',
width:200,
textAlign:'left',
font:{fontSize:14}
});
var arrowImage = Ti.UI.createImageView
({
image:'../iphone/appicon.png',
width:20,
height:20,
left:280,
top:30
});
nameLabel.text = categoryName;
getDetailsData(addressLabel);
row.add(placeImage);
row.add(nameLabel);
row.add(addressLabel);
row.add(arrowImage);
tableData[i] = row;
//set page title for each row
row.pageTitle = tableData[i];
row.pageAddress = tableData[i];
}
tableView.setData(tableData);
};
//PlaceList.js
var currentWindow = Titanium.UI.currentWindow;
//retrive index value
var index = Titanium.App.Properties.getInt('index');
Ti.API.log('NextView Index:'+index);
var title = Titanium.App.Properties.getString('title');
Ti.API.log('CheckInView Title:'+title);
var address = Titanium.App.Properties.getString('address');
Ti.API.log('CheckInView Address:'+address);
My problem is that I can't get row title in next window but I get index value of that row so please give me idea how to fetch it.
Just do this after the following line:
var row = Titanium.UI.createTableViewRow({height:'auto'});
Set a title as property of your row like this:
row.pageTitle = tableData[i];
And in click event you can get this property like this:
myTableView.addEventListener('click',function(e)
{
e.rowData.pageTitle
}
Hello friends,
I am developing an app in Titanium Studio sdk 1.8.1 using Google Place API to display category atm list & address in tableview so I use json parsing using this link but loader.onload function of getData method is not called immediately after send function of getData method in json parsing so its called after getDetailsData() function and also can't display address in tableview so please give me idea how to solve it.
Thanks in advance.
var lat ,lon ,radius , name , sensor , key , reference, address;
lat = '-33.8670522';//'23.042067';
lon = '151.1957362';//'72.530835';//
radius = '500';
name = title;
sensor = 'false';
key = 'AIzaSyDALrXHC4uMtfSrpCg6NHxqPhsLccLYPZE';
var rowData = [];
// getCategoryData using Google Place API
function getData()
{
var loader = Titanium.Network.createHTTPClient();
var url = "https://maps.googleapis.com/maps/api/place/search/json?";
url = url + "location=" + lat + ',' + lon;
url = url + "&radius=" + radius;
url = url + "&name=" + name;
url = url + "&sensor=" + sensor;
url = url + "&key=" + key;
Ti.API.info(url);
// Sets the HTTP request method, and the URL to get data from
loader.open("GET",url);
// Create our HTTP Client and name it "loader"
// Runs the function when the data is ready for us to process
loader.onload = function()
{
var obj = JSON.parse(this.responseText);
Ti.API.log(obj);
var results = obj.results;
Ti.API.log(results);
for (var i = 0; i < results.length; i++)
{
var name = obj.results[i].name;
reference = obj.results[i].reference;
Ti.API.log('Refernce:'+reference);
getDetailsData();
// Create a row and set its height to auto
var row = Titanium.UI.createTableViewRow({height:'auto'});
// Create the view that will contain the text and avatar
var post_view = Titanium.UI.createView({
height:'auto',
layout:'vertical',
top:5,
right:5,
bottom:5,
left:5
});
// Create the label to hold the tweet message
var nameLabel = Titanium.UI.createLabel({
//text:name,
left:30,
top:0,
bottom:2,
height:'auto',
width:236,
textAlign:'left',
font:{fontSize:14}
});
// Create the label to hold the tweet message
var addressLabel = Titanium.UI.createLabel({
text:'Address',
left:30,
top:0,
bottom:2,
height:'auto',
width:236,
textAlign:'left',
font:{fontSize:14}
});
nameLabel.text = name;
//addressLabel.text = placeAddress;
post_view.add(nameLabel);
post_view.add(addressLabel);
// Add the post view to the row
row.add(post_view);
// Give each row a class name
//row.className = "item"+i;
// Add row to the rowData array
rowData[i] = row;
//rowData.push(row);
}
//tableView.setData(rowData);
// Create the table view and set its data source to "rowData" array
var tableView = Titanium.UI.createTableView({data:rowData});
//Add the table view to the window
showWin.add(tableView);
};
//-- Network error
loader.onerror = function(e)
{
Ti.API.info('Network error: ' + JSON.stringify(e));
};
// Send the HTTP request
loader.send();
}
function getDetailsData ()
{
var loader1 = Titanium.Network.createHTTPClient();
Ti.API.log('getDetailsData');
var url = "https://maps.googleapis.com/maps/api/place/details/json?";
url = url + "reference=" + reference;
url = url + "&sensor=" + sensor;
url = url + "&key=" + key;
Ti.API.info(url);
// Sets the HTTP request method, and the URL to get data from
loader1.open("GET",url);
// Runs the function when the data is ready for us to process
loader1.onload = function()
{
var detailsObj = JSON.parse(this.responseText);
Ti.API.log(detailsObj);
address = detailsObj.result.formatted_address;
Ti.API.log('Address:'+address);
phoneno = detailsObj.result.formatted_phone_number;
Ti.API.log('Phone No:'+phoneno);
};
//-- Network error
loader1.onerror = function(event)
{
Ti.API.info('Network error: ' + JSON.stringify(event));
};
// Send the HTTP request
loader1.send();
return address;
}
getData();
Dont't use the return in the second http request.
Pass the label object in the function like:
getDetailsData(addressLabel);
and set the text inside loader1.onload like this:
address = detailsObj.result.formatted_address;
addressLabel.text = address;