I am building a jqgrid that needs different background (or in general, a different css class) value for specific cells. I know which cells need the class applied at generation time of the data being sent down to jqgrid. What I would like is to be able to indicate a class within the jqgrid rows structure for each specific cell:
<rows>
<page> </page>
<total> </total>
<records> </records>
<row>
<cell>1.00</cell>
<cell class='errorClass'>15.00</cell>
<cell class='warningClass'>9.00</cell>
…
</row>
<row>
<cell>1.00</cell>
<cell>2.00</cell>
<cell>1.15</cell>
…
</row>
…
</rows>
I know I can do this formatting after the data is sent down, but I would like to see the grid drawn with the formatting in place rather than after the fact.
I’ve achieved something like what I want by setting using a tag within the cell:
<cell><span class='warningClass'>3.00</span></cell>
But it does not set the class for the entire cell, just data within, with only the text highlighted and not the entire cell.
I ind your question interesting so I made the demo for you.
If you want to set some custom attributes on the grid cells (
<td>elements) likeclass,title,colspan,stylethe cellattr is the best way to do this (see here for details).cellattrare close to custom formatter feature, but allows to define attributes of the cell and not the cell contain.In the demo I used the following XML input:
and the
cellattrlike the followingIn the case the ‘class’ attribute of the second (‘:eq(1)’) cell will be used for the formatting.
From the design point of view I would recommend you don’t use the class names directly as the attributes. An alternate attribute like
format="error"which will be converted asclass='ui-state-error'have some advantages. It could make separation of information like formatting tips from direct HTML instruction.