0

I am using jqGrid to display some data. I want to change the color of the text when the data of some columns matches some condition. In order to achieve this, I do the following thing:

loadComplete: function () {
if (rowData['col1'] === "true") {
$('#list').jqGrid('setRowData', rowIds[i], false, { 'color': 'red', 'font-   style': 'italic'  });

... }

I works for the first page. But I have several pages of the data and when I do either paging or filtering I loose this functionality: the color is black again. I tried to use the other events I found: onPaging, gridComplete and they don't fire at all. I also tried to use the formatter for each column e.g.:

{
name: 'col1',
index: 'col1',
width: '50',      
formatter: function (cellvalue, options, rowObject) {
if (rowData['col5'] === "true") {
return "<i>"+cellvalue+"</i>";
...}

But this does not work because when I am in col1 I can not check the value of col5 Please advise.

J.Doe
  • 33
  • 2
  • 8
  • Which version of jqGrid and which fork ([free jqGrid](https://github.com/free-jqgrid/jqGrid), [Guriddo jqGrid JS](http://guriddo.net/?page_id=103334) or some old version <=4.7) you use? Which jqGrid parameters you use (`datatype`, `loadonce`)? Which format have input data which you use to fill the grid. In `formatter`, which you posted, have 3-d parameter with the name `rowObject`, but you use `rowData['col5']` instead of `rowObject.col5`. – Oleg Oct 27 '15 at 07:53
  • * jqGrid 4.6.0 - jQuery Grid * Copyright (c) 2008, Tony Tomov, tony@trirand.com * Dual licensed under the MIT or GPL licenses * http://www.opensource.org/licenses/mit-license.php * http://www.gnu.org/licenses/gpl-2.0.html * Date:2014-02-20 – J.Doe Oct 27 '15 at 07:56
  • The usage of `cellattr` in `colModel` is better as the usage of `setRowData`. See [the old answer](http://stackoverflow.com/a/12180842/315935) for the corresponding code example. – Oleg Oct 27 '15 at 07:58
  • As you suggested I added the following into the model: cellattr: function (rowId, val, rawObject) { return " style='color: red !important;'";} Without providing any condition, just to check if it would effect the color change. Nothing happens at all. Did I miss something? – J.Doe Oct 27 '15 at 08:39
  • You should provide **the demo** which reproduces the problem. I suppose that you make some simple errors like placing `cellattr` on the wrong place or some other error in the part of the code which you don't posted before. For example it's important to know **how you fill the grid**. You need at least append the text of your question which shows how you fill the grid, which parameters of jqGrid you use (`datatype`, `loadonce` are really required) and which format have the input data (`[{id: "123", name:"Test", ...}, ...]` or `[{id: "123", cell: ["Test", ...]}, ...]`). – Oleg Oct 27 '15 at 09:36
  • So the paging events do not work and cellattr does not make any change... – J.Doe Oct 27 '15 at 09:52
  • This is the code related to cellattr: { name: 'col1', index: 'col1', hidden: true, align: 'left', width: '50', sorttype: 'text', search: false cellattr: function (rowId, val, rawObject) { return ' style="color:red !important;background: green;"'; } }, – J.Doe Oct 27 '15 at 09:54
  • You should click on **edit** link below of the text of the question and modify the text. You should include the code which you use in the text of your question instead of including it in the comment which makes formatting unreadable. Moreover I wrote you multiple times which information is *really required* to know to be able to help you, but you ignore this. Why? I wrote that it's really important to know **how you fill the grid**. Do you use `data` parameter of jqGrid or you use `addRowData` for example? Wrong filling the grid could be the reason of your problem. – Oleg Oct 27 '15 at 10:14
  • You should post **the answer** on your own question only if you found the solution of the problem. In all other cases you should click on "edit" button/link **below of your question** and modify *the text of the question*. – Oleg Oct 27 '15 at 10:40
  • I will stop my attempts to help you if you continue to ignore my question. – Oleg Oct 27 '15 at 10:45
  • Oleg, sorry, I guess I did not understand your question. I did not use jqGrid before and now I faced with somebody's code where I don't have a full understanding of what is going on. – J.Doe Oct 28 '15 at 10:26
  • You should just click on **edit** button/link below of the text of your question, modify the text of your original question and append it with **more full code which you use**. I posted you the link with old question which demonstrates the usage of `cellattr`. [The demo](http://www.ok-soft-gmbh.com/jqGrid/OK/AddClassToColumn46_.htm) set class in one column and uses your `" style='color: red !important;'"` settings in another column. You can see that the code work in jqGrid 4.6. If you want that other people help you you should provide full information about what you do. – Oleg Oct 28 '15 at 10:43

0 Answers0