Hello Tony,
I suggest to allow to use string values for cellattr and rowattr in the same way like one can now to use strings as the value for template (see the pull request):
|
1 2 3 4 5 6 7 8 9 10 11 12 |
$.extend($.jgrid,{<br /> cellattr: {<br /> someCellAttrValue: function (rowId, val, rawObject) {<br /> ...<br /> }<br /> },<br /> rowattr: {<br /> someRowAttrValue: function (rd) {<br /> ...<br /> }<br /> }<br /> }); |
The corresponding changes in jqGrid code are very easy. To allow the usage string values for cellattr one need to change the line
|
1 |
var cm = ts.p.colModel[pos], |
to
|
1 |
var cm = ts.p.colModel[pos], cellAttrFunc, |
and the lines
|
1 2 3 |
} <span class="k">else</span> <span class="k">if</span> (cm.cellattr <span class="o">&&</span> $.isFunction(cm.cellattr))<br /> {<br /> celp <span class="o">=</span> cm.cellattr.<span class="nf">call</span>(ts, rowId, tv, rawObject, cm, rdata); |
to the following
|
1 2 3 |
} else if ($.isFunction(cm.cellattr) || (typeof cm.cellattr === "string" && $.jgrid.cellattr != null && $.isFunction($.jgrid.cellattr[cm.cellattr]))) {<br /> cellAttrFunc = $.isFunction(cm.cellattr) ? cm.cellattr : $.jgrid.cellattr[cm.cellattr];<br /> celp = cellAttrFunc.call(ts, rowId, tv, rawObject, cm, rdata); |
In the same way to allows the usage of string as the value of rowattr one need to change the lineÂ
|
1 |
rowAttrObj <span class="o">=</span> $.isFunction(ts.p.rowattr) <span class="o">?</span> ts.p.rowattr.<span class="nf">call</span>(ts, rd, cur, id) <span class="o">:</span>{}; |
to the lines
|
1 2 3 |
rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :<br /> (typeof ts.p.rowattr === "string" && $.jgrid.rowattr != null && $.isFunction($.jgrid.rowattr[ts.p.rowattr]) ?<br /> $.jgrid.rowattr[ts.p.rowattr].call(ts, rd, cur, id) : {}); |
One can modify the code more to allow to use cellattr and rowattr as comma-separated string with the values $.jgrid.cellattr and $.jgrid.rowattr. In the way one could allow applying of multiple callback functions (the stack) at once. In general such extension could have sense for formatter and template values too.
The demo demonstrates the changes working.
Best regards
Oleg
Copyright 2014 TriRand LtdAll Rights ReservedRSS
Back to Top