I am using a custom formatter for my jqGrid columnModel and I can't get sorting to work with formatter functions. If I remove formatter column sorts normally.
jQuery("#listAgentOptions").jqGrid({
height: 240,
datatype: "local",
colNames: [' ', 'First Name', 'Last Name', 'Role'],
colModel: [
{ name: 'status', index: 'status', width: 18, sorttype: 'text', align: 'center', formatter: function(cellvalue, options, rowObject) {
return cellvalue == 1 ? "<img src='images/agent_green_s.png' alt='Ready' title='Ready' />" :
cellvalue == 3 ? "<img src='images/agent_red_s.png' alt='Busy' title='Busy' />" :
"<img src='images/agent_orange_s.png' alt='Pending Ready' title='Pending Ready' />";
},
unformat:
function(cellvalue, options, rowObject) { return Math.floor(Math.random() + 0.1).toString(); }
},
{ name: 'firstName', index: 'firstName', width: 92 },
{ name: 'lastName', index: 'lastName', width: 142 },
{ name: 'role', index: 'role', sorttype: 'int', width: 36, align: 'center', formatter: function(cellvalue, options, rowObject) {
return cellvalue == true ? "<img src='images/user_gray.png' alt='Supervisor' title='Supervisor' />" : "<img src='images/user.png' alt='Agent' title='Agent' />";
}, unformat:
function(cellvalue, options, rowObject) { return cellvalue; }
}
],
sortname: 'lastName'
});
Rows are added like this:
jQuery("#listAgentOptions").jqGrid('clearGridData');
$.each(result, function(i, item) {
if (item.ContactType == 1) {
jQuery("#listAgentOptions").jqGrid('addRowData', i+1, { firstName: item.ContactName.split(" ")[0], lastName: item.ContactName.split(" ")[1],
role: item.IsSupervisor,
status: item.Status == "Ready" ? 1 : item.Status == "Busy" ? 3 : 2
});
}
});
How do I get sorting to work properly?
Update. I have just downloaded the latest version of jqGrid - same issue.
I have also tried using unformat: function(cellvalue, options, rowObject) { }
but cellvalue is empty there :-E When I use return Math.floor(Math.random() + 0.1).toString();
it does sort things randomly (each time I click), but return cellvalue;
just returns an empty string.