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_Related Related Topics sp_TopicIcon
Jqgrid how to retain cellattr conditional formatting while the datatype is local (or loadonce: true)?
17/10/2012
04:20
Avatar
casbby
Member
Members
Forum Posts: 3
Member Since:
17/10/2012
sp_UserOfflineSmall Offline

I have a jqgrid load a large amount of rows (in 1000s) with loadonce:true option. The user will operate on the data locally after the jqgrid is loaded. I also have a conditional formating on one of the column with somthing looks like this

cellattr: function(rowId, cellValue, rawObject, cm, rdata) { if (rawObject[0]=='Stale'){ return ' class="stale-highlight"'; } else if (rawObject[0]=='Not Stale') { return ' class="notstale-highlight"'; } }

It works fine except the conditionall formatting will be lost as soon as the user does sort, filter, etc.

I know this may be related to the loadonce option which changes the datatype to local after the grid is loaded. What can I do to allow the user operate operate on the data without polling the servrr but still retains the conditional formating?

Thanks Casbby

17/10/2012
09:53
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

The problem here is that you have a jsonReader with repeat items set to true.

When the data is added in the loacal data array it is added by name.

In order to work this I would suggest you to use record data parameter (rdata) where it definition is with name:value pair.

The code can look like this

cellattr : function(rowId, cellValue, rawObject, cm, rdata) {

if(rdata['myfirstfield'] )== 'Stale'  {

    return 'something';

} else if(...) {

....

}

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

21/10/2012
02:32
Avatar
joshbodine
Member
Members
Forum Posts: 7
Member Since:
20/04/2012
sp_UserOfflineSmall Offline

When is use the following in cellattr

rdata['name_of_my_column']

I get an undefined error. What I am doing wrong?

22/10/2012
14:22
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello,

In order to see what you have, please use a FireFox FireBug and cosole.log the rdata something like this:

cellattr : function(rowId, cellValue, rawObject, cm, rdata) {

console.log( rdata );

}

The open the console to see the data.

Regards

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

22/10/2012
22:58
Avatar
joshbodine
Member
Members
Forum Posts: 7
Member Since:
20/04/2012
sp_UserOfflineSmall Offline

I actually already did that and when I add console.log(rdata) all I get returned is "true" (no quotes) 

22/10/2012
23:45
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

You are right joshbodine,

the current implementation of jqGrid calls cellattr here inside of code of formatCol, but the formatCol will be called everywhere (for example here) with true as rdata with exception of the line which fill the footerrow where the rdata is false. So rdata have always boolean value.

It was some old code where rdata was filled as object, but the code was changed.

So I recommend you to use prity simple way to make cellattr working in both cases: initial filling from the server with jsonReader: {repeatitems: true} togather with the usage loadonce: true. What you can do is just testing the type of rawObject. If rawObject is array then you have initial filling and should use syntax like rawObject[0]. If rawObject is not array then the datatype is already changed to "local" bacause of usage loadonce: true and you should access the row of data per name: rdata.columnNameOfFirstColumn. The code is close to the code from the answer where custom formatter are used. In your case the code will be about the following:

cellattr: function (rowId, cellValue, rawObject) {
    var dataFromFirstCol = $.isArray(rawObject) ? rawObject[0] : rdata.columnNameOfFirstColumn;
    if (dataFromFirstCol === 'Stale'){
        return ' class="stale-highlight"';
    } else if (dataFromFirstCol === 'Not Stale') {
        return ' class="notstale-highlight"';
    }
}

Best regards
Oleg 

23/10/2012
00:12
Avatar
casbby
Member
Members
Forum Posts: 3
Member Since:
17/10/2012
sp_UserOfflineSmall Offline

Thank you all for the knowledge. I relised because i used the sequential array for cell array, the columnName only bcomes accessible after the initial load. (which means after the inital load the rawObject[0], instead of pointing the first column in the cell, it is now pointing to the first column name).

my workaround is not as elegant as Oleg's solution.

cellattr: function(rowId, cellValue, rawObject, cm, rdata) { if (rawObject[0]=='Stale' || rawObject.column_name=='Stale') { return ' class="stale-highlight"'; } else if (rawObject[0]=='Not Stale' || rawObject.column_name=='Not Stale') { return ' class="notstale-highlight"'; }
23/10/2012
01:09
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

In my opinion the problem with different format of rawObject is common problem of custom formatters, cellattr and rowattr. It could be easy solved by dividing the lines of code in the loop in two loops: in the fisrt one one could fill rd without calling of addCell and in the second loop one could call addCell with rd as additional parameter. rd will be the object with named properties and so it could be forwarded to formatCol and to custom formatters and cellattr.

I suggested the approch before in some my old change requestes, but I couldn't get Tony to convince to implement the changes.

Best regards
Oleg 

23/10/2012
09:39
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Thanks Oleg,

Sorry, but I missed this post. Will try to fix this today.

Best Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

23/10/2012
09:50
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

joshbodine,

Just fixed the problem. Could you ples check if everthing if fine for you now.

You can get the code from GitHub.

Thanks

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

23/10/2012
10:55
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

Hello Tony,

the which you currently published on github contains one loop where addCell just contails additional parameter rd. The problem is that rd is not yet full filled. It contains only the named properties of the previous columns and contains no information about next columns. I can't imagine, that one can solve the problem without deviding the corresponding loop in two loops like I described before.

Additionally I think that one have to adjust the code of addRowData too in the place where folmatCol will be called (about here).

Best regards
Oleg
P.S. I wanted remind you Tony about another my previous suggestion. If you find the time could you take a look at it.

23/10/2012
11:45
Avatar
tony
Sofia, Bulgaria
Moderator
Members

Moderators
Forum Posts: 7721
Member Since:
30/10/2007
sp_UserOfflineSmall Offline

Hello Oleg,

Thanks for remind me.

Right now I remember this discussion about cellattr rdata parmeter. Humm ....

Regards

Tony

For professional UI suites for Java Script and PHP visit us at our commercial products site - guriddo.net - by the very same guys that created jqGrid.

24/10/2012
08:37
Avatar
OlegK
Germany
Member
Members
Forum Posts: 1255
Member Since:
10/08/2009
sp_UserOfflineSmall Offline

By the way Tony, the discussion about the subject you can read here. In my tests introduction of two loops instead of one loop brought no performance decreasing. The first loop fill read input data with respect of $.jgrid.getAccessor and save results in the object rd. The second loop read the properties from rd, call addCell and save results in rowData.

Regards
Oleg 

Forum Timezone: Europe/Sofia

Most Users Ever Online: 715

Currently Online:
43 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