I have a JQGrid populated with data working correctly. The default sorting functionality is working as expected. However, I would like to sort by the clicked column, and the by a name column; every time. I think the onSortCol
is where I should start, but there isn't much in the documentation about how to sort the contents of the table. Ideally, I would like to not have to write my own sorting algorithm and just plug into the JQGrid API somehow. All of the data is on the client and I would like to avoid a trip to the server if at all possible.
Here is the code I'm using to create the grid:
$jqGrid = $('#people_SelectedContacts').jqGrid({
ajaxGridOptions: {
type: "POST"
},
url: 'AJAX/GetContacts',
datatype: "json",
postData: JSON.stringify({ ID: $('#ID').val() }),
loadonce: true,
sortable: true,
caption: "Selected Contacts",
hidegrid: false,
autowidth: true,
rowNum: 10000,
height: "100%",
loadui: 'block',
colNames: ['lecID', 'lrlID', 'mjID', 'Role', 'Name', 'Entity', 'Contact', 'D #', ''],
colModel: [
{ name: 'LECID', hidden: true },
{ name: 'LRLID', hidden: true },
{ name: 'MJID', hidden: true },
{ name: 'RoleLookupName', index: 'RoleLookupName' },
{ name: 'FullName', index: 'FullName' },
{ name: 'Entity', index: 'Entity' },
{ name: 'ContactInformation', index: 'ContactInformation' },
{ name: 'DNumber', index: 'DNumber' },
{ name: 'Remove', sortable: false, width: 25 }
],
jsonReader: {
root: 'ReturnValues.Contacts',
repeatitems: false
},
beforeProcessing: function (data, status, xhr) {
if (!data.ReturnValues.Contacts) {
data.ReturnValues.Contacts = new Array();
}
$.each(data.ReturnValues.Contacts, function (index, value) {
value.Entity = FormatAddress(value);
value.ContactInformation = FormatContact(value);
value.DNumber = FormatDocket(value);
});
},
gridComplete: function () {
var ids = $jqGrid.jqGrid('getDataIDs');
for (var i = 0; i < ids.length; i++) {
removeButton = $('<span>').addClass('remove-contact jqui-button-fix');
$jqGrid.jqGrid('setRowData', ids[i], { Remove: $('<div>').append(removeButton).html() });
}
},
loadComplete: function (data) {
},
onSortCol: function (index, iCol, sortorder) {
}
});
See Question&Answers more detail:
os