I've been having problems getting jqGrid to sort. I'd like to preferable do this sorting on the client, but I'm also willing to make a new call to the database to get the sorted results as well.
I can click on the column headers and the sort arrows change directions, however the data does not change at all.
I've looked over this question, however calling reloadGrid didn't seem to help.
My entire grid is as follows:
var x = $("#grid").jqGrid({
jsonReader: { root: "rows", repeatitems: false },
datatype: "json",
height: 'auto',
autowidth: true,
forceFit: true,
colNames:['ID','Name'],
colModel:[
{name:'id', key:true, index:'id', width:60, sorttype:"int", jsonmap:"id"},
{name:'name', index:'name', width:90, jsonmap: "name"}
],
caption: "Results",
loadonce: true,
sortable: true,
loadComplete: function() {
jQuery("#grid").trigger("reloadGrid"); // Call to fix client-side sorting
}
});
//This data comes from a web service call, hard coding in to test
var jsonData = [
{id: 1, name: 'Apple'},
{id: 2, name: 'Banana'},
{id: 3, name: 'Pear'},
{id: 4, name: 'Orange'}
];
x[0].addJSONData( { rows: jsonData } );
See Question&Answers more detail:
os 与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…