EDIT : I found out how, answer's below
I tried looking at other questions but can't figure how to solve my problem.
I load jqGrid with json datas. Here is an example of the json file :
{"statut" : "Inactive","name" : [{"LinkType":"user", "LinkText":"DINGO", "LinkSrc":"9443"}], "bands":""},
{"statut" : "Active","name" : [{"LinkType":"user", "LinkText":"BONNIE", "LinkSrc":"8591"}],"bands" : [{"LinkType":"band", "LinkText":"PARADE","LinkSrc":"PARADE"},{"LinkType":"band", "LinkText":"GLORIA KILLS", "LinkSrc":"gloria kills"}]}
...
On the jqGrid, the settings are these ones :
$("#table").jqGrid({
datatype: 'json',
url : 'json.php',
regional: 'fr',
filtering: true,
sorting: true,
paging: true,
autoload: true,
pageSize: 15,
pageButtonCount: 5,
ignoreCase: true,
height: '100%',
loadonce: true,
gridview: true,
colModel: [
{name: 'statut', label : 'Statut', width:100, align: 'center', stype:'select', searchoptions:{value:':All;Inactive:Inactive;Active:Active'}},
{name: 'name', label : 'Name', formatter: MyLinkFormater, unformat: MyLinkUnformater},
{name: 'bands', label : 'Bands', formatter: MyLinkFormater, unformat: MyLinkUnformater}
],
pager: '#pager',
rowList:[10,20,30,40,50,100,200,300,400,500,1000,5000],
});
jQuery("#table").jqGrid('filterToolbar', { stringResult: true, searchOnEnter: false, defaultSearch: "cn" });
And here are the functions :
function MyLinkFormater(cellvalue, options, rowObject) {
var i, res = "", linkInfo, preLink;
if (cellvalue == null || !$.isArray(cellvalue)) {
return " "; // empty cell in case or error
}
for (i = 0; i < cellvalue.length; i++) {
linkInfo = cellvalue[i];
if(linkInfo.LinkType == 'band') {
preLink = '?page=showBand&band=';
}
if(linkInfo.LinkType == 'user') {
preLink = '?page=showUser&e=1&id=';
}
res += (res.length > 0 ? ", " : "") +
'<a href="' + preLink + linkInfo.LinkSrc + '" >' + linkInfo.LinkText + '</a>';
}
return res;
}
function MyLinkUnformater(cellvalue, options, cell) {
return $('a', cell).text();
}
Everything works fine except searching/sorting the Name or Bands column. I can't figure what I should do. Do I have to use beforeSearch and if yes, what should I do ?
Any help welcome, this is driving me crazy.