Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I ind your question interesting so I made <a href="http://www.ok-soft-gmbh.com/jqGrid/XmlCellAttr.htm" rel="nofollow noreferrer">the demo</a> for you.</p> <p><img src="https://i.stack.imgur.com/MG7LJ.png" alt="enter image description here"></p> <p>If you want to set some custom attributes on the grid cells (<code>&lt;td&gt;</code> elements) like <code>class</code>, <code>title</code>, <code>colspan</code>, <code>style</code> the <a href="http://www.trirand.com/jqgridwiki/doku.php?id=wiki:colmodel_options" rel="nofollow noreferrer">cellattr</a> is the best way to do this (see <a href="https://stackoverflow.com/questions/5281101/how-to-set-the-cell-background-color-baced-on-the-cell-value-in-jqgrid/5281391#5281391">here</a> for details). <code>cellattr</code> are close to <a href="http://www.trirand.com/jqgridwiki/doku.php?id=wiki:custom_formatter" rel="nofollow noreferrer">custom formatter</a> feature, but allows to define attributes of the cell and not the cell contain. </p> <p>In <a href="http://www.ok-soft-gmbh.com/jqGrid/XmlCellAttr.htm" rel="nofollow noreferrer">the demo</a> I used the following XML input:</p> <pre><code>&lt;?xml version='1.0' encoding='utf-8'?&gt; &lt;rows&gt; &lt;page&gt;1&lt;/page&gt;&lt;total&gt;1&lt;/total&gt;&lt;records&gt;2&lt;/records&gt; &lt;row id='13'&gt; &lt;cell&gt;1.00&lt;/cell&gt; &lt;cell class='ui-state-error'&gt;15.00&lt;/cell&gt; &lt;cell&gt;9.00&lt;/cell&gt; &lt;/row&gt; &lt;row id='12'&gt; &lt;cell&gt;1.00&lt;/cell&gt; &lt;cell&gt;2.00&lt;/cell&gt; &lt;cell class='ui-state-highlight'&gt;1.15&lt;/cell&gt; &lt;/row&gt; &lt;/rows&gt; </code></pre> <p>and the <code>cellattr</code> like the following</p> <pre><code>cellattr: function () { var c = $('cell:eq(1)', arguments[2]).attr('class'); return c ? " class='" + c + "'": ""; } </code></pre> <p>In the case the 'class' attribute of the second (':eq(1)') cell will be used for the formatting.</p> <p>From the design point of view I would recommend you don't use the class names directly as the attributes. An alternate attribute like <code>format="error"</code> which will be converted as <code>class='ui-state-error'</code> have some advantages. It could make separation of information like formatting tips from direct HTML instruction.</p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload