This is a question that I know has been asked here and several other places on the internet. I have tried all of the solutions I could find on the StackOverflow site with the same result, nothing solved my problem.
I want to load the data from the database once, and then do all of the sorting operations on the client. The loadonce property sounds like it is supposed to handle this, but it doesn’t seem to be working for me. I’ve also tried setting the datatype to local in various event handlers with no success.
Here is the code I am using to instantiate the grid.
$('#people_SelectedContacts').jqGrid({
ajaxGridOptions:{
type: "POST"
},
datatype: function(data){
$.ajax(klg.getAppRoot()+"AJAX/GetMatterProfileContacts",{
data: JSON.stringify({
MatterProfileID: $('#MatterProfileID').val()
}),
success: function(data){
var contacts = data.ReturnValues;
var mygrid = $("#people_SelectedContacts")[0];
mygrid.addJSONData(contacts);
},
complete: function(){
$("#people_SelectedContacts").setGridParam({datatype:'local'});
}});
},
loadonce: true,
colNames:['lecID','lrlID','mjID','Role','Name','Company/Court', 'Business Phone', 'Email', 'Docket #'],
colModel:[
{name:'LegalEntityContactID', hidden:true},
{name:'LegalRoleLookupID', hidden:true},
{name:'MatterJurisdictionID', hidden:true},
{name:'LegalRoleLookupName', index:'legalrole'},
{name:'FullName',index:'name'},
{name:'Company',index:'company'},
{name:'BusinessPhone',index:'bussphone'},
{name:'Email',index:'email'},
{name:'DocketNumber',index:'email'}
],
sortable: true,
jsonReader: {
root:'MatterProfileContacts',
repeatitems: false,
id:"MatterProfileContactID"
}
});
The data loads into the grid correctly, but as I said, the sorting commands all go and hit the server again. Can anyone point my in the right direction? The only reason I switched from a standard HTML table to the JQGrid is for sorting and grouping. If I can’t get client-side sorting to work, it’s useless.
Thank you Stack Overflow community.
I changed the grid to use datatype: ‘json’ as you suggested by Oleg. I still had the sorting problem but I realized that it was because of the
indexvalues I was using in the column model. Theindexvalues of the column model has to match the property names of the JSON objects being returned from the server.