Forum

November 2nd, 2014
A A A
Avatar

Lost password?
Advanced Search

— Forum Scope —




— Match —





— Forum Options —





Minimum search word length is 3 characters - maximum search word length is 84 characters

The forums are currently locked and only available for read only access
sp_Feed Topic RSS sp_TopicIcon
allow to use strings as values of cellattr and rowattr
09/11/2014
15:02
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

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

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
21 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.com

Moderators: tony: 7721, Rumen[Trirand]: 81

Administrators: admin: 66

Comments are closed.
Privacy Policy   Terms and Conditions   Contact Information