Forum
06:03
26/08/2009
hi all, I am using jqGrid with asmx web services…because services need to be called on specific way, I am using datatype parameter as a function call in which I am calling web service using jquery $.ajax method
Here is my code:
$.ajax({
url: 'Default.aspx/GetPersons',
data: “{}”,
type: “POST”,
dataFilter: function(data) {
var msg = eval('(' + data + ')');
if (msg.hasOwnProperty('d'))
return msg.d;
else
return msg;
}
everything works fine, I am getting json from the server and grid display
everything as suppose to. But, from some strange reason,
I can't accomplish sorting on client via loadonce: true attribute, for
every event on grid, grid calls server...
Any ideas how to solve this?
cheers
Marko
09:59
Moderators
30/10/2007
Hello,
loadonce work only with the predefined loaders. If you use datatype as function you should set datatype:local manually after the first loading of the grid with the custom function. Something like:
datatype : function (){
$.ajax({
...
complete :function (...){
.....
$("#mygrid").setGridParam({datatype:'local'});
}
})
},
Best Regards
Tony
For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.
02:02
13/02/2010
I had the same need as the original poster. Tony's reply shows the datatype needed to be set to local for the grid to sort client side.
I did the following that way I could have local sorting, but have ajax requests to be fired in other scenarios.
// loadGrid anonymous function
var loadGrid = function(postdata) {
… code ajax request, whatever..
}
$("#mygrid").jqGrid({
datatype: loadGrid,
rowNum: -1, // show all rows
loadonce: true, // disabled paging and all sorting done locally
… other jqGrid options,
onSortCol: function(index, iCol, sortorder) {
//
// Grid loaded all records, so sort locally
// Re-Wire datatype for ajax in Grid Complete
$("#mygrid").setGridParam({ datatype: 'local' });
},
gridComplete: function() {
//
// Rewire datatype to ajax function
if ($("#mygrid").getGridParam("datatype") === "local")
$("#mygrid").setGridParam({ datatype: loadGrid });
}
With that in place your grid will switch to datatype: local when you click the sorting column and after completion it sets the grid back to the function that cotains your code and web service call.
Hope this helps others.
Most Users Ever Online: 715
Currently Online:
26 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66