I am trying to make a cell colored and clickable if it satisfies certain condition.
The problem that I am getting is in passing the parameter to the onclick of the element.
I am doing something like:
{
name: 'numberOfUnits',
index: 'numberOfUnits',
sorttype: 'integer',
cellattr: function (rowId, tv, rawObject, cm, rdata) {
if (...) {
return 'style="background-color:red" onClick="javascript:showReceivedLockedPieChartDialog(' + '\'' + lockedCellId + '\'' + ')"';
}
else {
return 'style="color:black"';
}
}
}
I see that the text is being formed as:
style="background-color:red" onClick="javascript:showReceivedLockedPieChartDialog('ABC')"
I see that it is creating something like this…
<td aria-describedby="reportGrid_numberOfUnits" title="13" ABC")"="" onclick="javascript:showReceivedLockedPieChartDialog(" style="background-color:red" role="gridcell">13</td>
Please help me pass the parameter to this function.
Ohh yes! Your code shows that the parting of string returned from
cellattrwill be parsed not carefully enough. I find that one should better rewrite the function formatCol which will be used internally. I wanted to post next time to trirand suggestion to change the code usingRegExmatching.Nevertheless there are some simple rules which could allow to use
cellattrin the current implementation:styleattribute as the last attribute in the string returned fromcellattr' 'blank as the first character of returned value if you returns not only the value for thestyleattribute.style,titleandclassonly as the names of the corresponding attributes.The last rule means that you should not use
class="mytitle"ortitle="my class style". The parsing of the returned string is not so careful. So such names will have some side effects. As I wrote before the corresponding part of the code jqGrid which parse the results should be changed in my opinion. I will try to post the corresponding suggestions to trirand in the next time.In your case you should rewrite the code of
cellattrtoThe demo shows that the changes works.