0

I have a jqgrid with a subgrid.

I am attempting to apply different colors to master and detail grids. I have two rules: the first one is to alternate odd and pair colors and the other one is to apply specific CSS to the row, based on values of a specific field.

Both master & details grid, contains the following gridComplete functions, where obviously childnodes index varies cause tables contains different fields:

gridComplete: function () {
            var _rows = $(".jqgrow");
            for (var i = 0; i < _rows.length; i++) {
                _rows[i].attributes["class"].value += " " + _rows[i].childNodes[4].textContent;
                _rows[i].attributes["class"].value += " " + _rows[i].childNodes[4].innerText;
            }
           applyZebra("jqTicketgrid");
        }

applyZebra function provides to alternate odd/pair colours and has already been tested on another grid which not contains a subgrid. For the record, I found above solutions in other solved questions of this forum, and both works with "simple" jqgrids (not master/detail).

PROBLEM The master grid is formatted only when I click to expand the detail rows, while detail subgrid never alternate colours, neither apply format based on cell contents...

Where I am wrong? Pheraps I must intercept another event which is not gridComplete? Otherwise with grid&subgrids it's impossible to use _rows[x] & childNodes[y] attributes?

Please ask for clarifications, if needed, thx.

Thanks in advance!

Larry
  • 573
  • 5
  • 14
  • 31

1 Answers1

0

I suppose the error in your code is that you use $(".jqgrow") instead of $(".jqgrow", this) where this inside of gridComplete will be either DOM element of the <table> of the grid or the subgid (I suppose you use grid as subgrid).

Additionally I would not recommend you to use you current code at all. It's much more effective and simple to to use cellattr. The rawObject parameter allow you access all other cells of the current row. In the answer you will find an example of implementation.

Community
  • 1
  • 1
Oleg
  • 220,925
  • 34
  • 403
  • 798
  • Thank you @Oleg! I tried to modify with $(".jqgrow", this), but it still does not work. About cellattr, I am trying to get it work and I agree with your interesting considerations. But I can't get it work. May you give me an example, please? I even tried to put this code into grid definition, but it does not work: cellattr: function (rowId, cellValue, rawObject, cm, rdata) { return ' class="A"'; } Thanks again! – Larry Jan 22 '12 at 14:41
  • Ok. I suceed to get it work **just for the cell**: I put the cellattr into colmodel, just to test: `cellattr: function (rowId, tv, rawObject, cm, rdata) { return 'class="A"'; }` and it works! **May you explain me how can I add class to the whole row, please?** Thank you very much @Oleg! – Larry Jan 22 '12 at 14:54
  • @Larry: I think I misunderstood your question. I suggested [here](http://www.trirand.com/blog/?page_id=393/feature-request/introduce-rowattr-jqgrid-like-cellattr-but-for-setting-attributes-on-tr-element-instead-of-td/#p25555) to introduce `rowAttr` which will be like `cellattr`, but for the whole row and not for the column. What you can use now is more as [this](http://stackoverflow.com/a/6575634/315935). – Oleg Jan 22 '12 at 15:10
  • Thank you! I am considering to wait rowAttr is introduced... I do not like the solution, I fear that can poorly perform... What do you think about a hybrid solution? I mean, in my case, to use cellattr to evaluate cellvalues and then apply class to the row... Do you think it is possible &/or more performing? May you give me a solution in that direction please? Thanks again, you are the best! – Larry Jan 22 '12 at 15:41
  • @Larry: Do you tried [the demo](http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridChangeRowBackgroundBasedOnCheckboxes.htm) from [the answer](http://stackoverflow.com/a/6575634/315935)? It should be very close to what you need. I am sure that you can modify the demo to implement what you need. The problem is that it could be many ways to solve your problem. The approach which you did at the beginning should also work if you would use `$(".jqgrow", this)`. If you have no success at the beginning you should just debug and find out the error. It should work. – Oleg Jan 22 '12 at 16:40
  • @Larry: You are welcome! Do you have success now? Is the problem solved? – Oleg Jan 25 '12 at 21:58
  • Yes, thank you! As you suggested `cellattr` solved my problems. I'll wait for rowattr implementation not being a strong need to highlight the entire row. – Larry Jan 30 '12 at 00:43