I have the following grid defined:
$("#list").jqGrid({
url:'listOpenQueryInXML.php',
datatype: 'xml',
colNames:['Id','name1', 'name2', 'status', 'type'],
colModel:[
{name:'id', index:'id', editable: false, formatter:'showlink', formatoptions:{baseLinkUrl:'continue.php'}},
{name:'name1', index:'name1', editable: false},
{name:'name2', index:'name2', editable: false},
{name:'status', index:'status', editable: false},
{name:'type', index:'type', editable: false}
],
autowidth: true,
sortname: 'id',
viewrecords: true,
pager: null,
sortorder: 'id',
loadonce: false,
caption: 'Open Query',
height: '100%',
xmlReader: { root : "rows", row: "row", repeatitems: false, id: "id" },
Now, what I would like to have is to override continue.php to be a different link based on the content of ‘id’, or ‘status’ or any field.
So if
status = NEW link=”new.php?id=”{id}”
status = STUCK link=”helper.php?id={id}”
Etc.
I’m running jqGrid 4.3.1 and jQuery 1.8.16.
You should use custom formatter instead of
showlinkformatter. In the case you have to construct<a>element yourself based on thecellvalue,optionsandrowObjectparameters of the callback function. Because you usedatatype: 'xml'therowObjectparameter will beIXMLDOMElementso to get contain of thestatusyou should use find or children jqGrid method.I don’t tested the code below, but I suppose you can do something like the following
Its only an example of the formatter. You can place for example other text in the link which will be displayed the user.
I removed from the jqGrid definition which you use many default options and added the
gridview: trueoptions which improves the performance of the grid.