Forum
04:20
17/10/2012
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
09:53
Moderators
30/10/2007
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.
14:22
Moderators
30/10/2007
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.
23:45
10/08/2009
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:
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
00:12
17/10/2012
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"'; }
01:09
10/08/2009
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
09:39
Moderators
30/10/2007
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.
09:50
Moderators
30/10/2007
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.
10:55
10/08/2009
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.
11:45
Moderators
30/10/2007
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.
08:37
10/08/2009
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
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.comModerators: tony: 7721, Rumen[Trirand]: 81
Administrators: admin: 66