Forum
15:02
10/08/2009
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):
$.extend($.jgrid,{ cellattr: { someCellAttrValue: function (rowId, val, rawObject) { ... } }, rowattr: { someRowAttrValue: function (rd) { ... } } });
The corresponding changes in jqGrid code are very easy. To allow the usage string values for cellattr one need to change the line
var cm = ts.p.colModel[pos],
to
var cm = ts.p.colModel[pos], cellAttrFunc,
and the lines
} else if (cm.cellattr && $.isFunction(cm.cellattr)) { celp = cm.cellattr.call(ts, rowId, tv, rawObject, cm, rdata);
to the following
} else if ($.isFunction(cm.cellattr) || (typeof cm.cellattr === "string" && $.jgrid.cellattr != null && $.isFunction($.jgrid.cellattr[cm.cellattr]))) { cellAttrFunc = $.isFunction(cm.cellattr) ? cm.cellattr : $.jgrid.cellattr[cm.cellattr]; 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Â
rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) :{};
to the lines
rowAttrObj = $.isFunction(ts.p.rowattr) ? ts.p.rowattr.call(ts, rd, cur, id) : (typeof ts.p.rowattr === "string" && $.jgrid.rowattr != null && $.isFunction($.jgrid.rowattr[ts.p.rowattr]) ? $.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
Most Users Ever Online: 715
Currently Online:
32 Guest(s)
Currently Browsing this Page:
1 Guest(s)
Top Posters:
OlegK: 1255
markw65: 179
kobruleht: 144
phicarre: 132
YamilBracho: 124
Renso: 118
Member Stats:
Guest Posters: 447
Members: 11373
Moderators: 2
Admins: 1
Forum Stats:
Groups: 1
Forums: 8
Topics: 10592
Posts: 31289
Newest Members:
, razia, Prankie, psky, praveen neelam, greg.valainis@pa-tech.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66