You can do much more than format the value with the formatter option as see in the doc. Let see with simple examples.
You want to change the css (color, font things…) of a cell in regard of his value.
“i want to have a red color for this cell if my client owe me money”.
|
1 2 3 4 |
{<br /> label: 'balance', name: 'balance', index: 'balance',<br /> formatter: isDebt<br /> }<br /> |
|
1 2 3 4 5 |
function isDebt(cellValue, options, rowObject) {<br /> if (cellValue !== Math.abs(cellValue)){<br /> options.colModel.classes = 'red-color';<br /> }<br /> }<br /> |
You want to change the css (color, font things…) of a cell in regard of another cell value.
Example “i want to have the background color of the age cell if this is the user anniversary (that is in column birth)”
|
1 2 3 4 5 6 7 8 9 |
function isBirth(cellValue, options, rowObject) {<br /> d2 = new Date();<br /> d1 = new Date(rowObject.birth);<br /> var diff = d2.getTime() - d1.getTime();<br /> if (d1.toDateString() === d2.toDateString()) {<br /> options.colModel.classes = 'annniversary-background-color';<br /> }<br /> return Math.floor(diff / (1000 * 60 * 60 * 24 * 365.25));<br /> }<br /> |
You have access to the whole row, values and properties.
You want more ? There it is.
$('#' + options.gid).jqGrid…
Enjoy.
PS: This would be awesome if this forum have some kind of tuto and script 'forum'. With code formatting plugin please. ๐
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top