Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p>The main ideas to change the background color of the row you will find <a href="https://stackoverflow.com/questions/4369899/jqgrid-zebra-alt-rows-background-not-working-due-to-ui-theme-class/4382122#4382122">here</a> and <a href="https://stackoverflow.com/questions/2931732/jqgrid-coloring-an-entire-line-in-grid-based-upon-a-cells-value/2936673#2936673">here</a>. I recommend you to read <a href="https://stackoverflow.com/questions/4942761/how-to-change-the-color-of-jqgrid-cell/4943722#4943722">this answer</a> which discussed different advantages and disadvantages of different approaches.</p> <p>To get column index from the column name you can use following simple function:</p> <pre><code>var getColumnIndexByName = function(grid, columnName) { var cm = grid.jqGrid('getGridParam','colModel'),i=0,l=cm.length; for (; i&lt;l; i++) { if (cm[i].name===columnName) { return i; // return the index } } return -1; }; </code></pre> <p>The function <code>getColumnIndexByName($("#list"), 'MyColumnName')</code> will get you the index in <code>colModel</code> of the 'MyColumnName' column.</p> <p>To change the background color you can follow the example</p> <pre><code>loadComplete: function() { $("tr.jqgrow:odd").addClass('myAltRowClass'); } </code></pre> <p>from <a href="https://stackoverflow.com/questions/4369899/jqgrid-zebra-alt-rows-background-not-working-due-to-ui-theme-class/4382122#4382122">the answer</a>, but instead of <code>':odd'</code> filter you can write the filter yourself using <a href="http://api.jquery.com/filter/" rel="nofollow noreferrer">jQuery.filter</a>. Inside of the filter you can use <a href="http://api.jquery.com/nth-child-selector/" rel="nofollow noreferrer">:nth-child()</a> to access the data from the corresponding <code>&lt;td&gt;</code> element (see <a href="https://stackoverflow.com/questions/5010761/linking-from-a-column-value-in-jqgrid-to-a-new-page-using-get/5017528#5017528">here</a>)</p> <p><strong>UPDATED</strong>: You can do the following (very close to the code from <a href="https://stackoverflow.com/questions/5664587/jqgrid-load-large-data-set-without-pagination/5690583#5690583">the another answer</a>):</p> <pre><code>loadComplete: function() { var iCol = getColumnIndexByName($(this),'closed'), cRows = this.rows.length, iRow, row, className; for (iRow=0; iRow&lt;cRows; iRow++) { row = this.rows[iRow]; className = row.className; if ($.inArray('jqgrow', className.split(' ')) &gt; 0) { var x = $(row.cells[iCol]).children("input:checked"); if (x.length&gt;0) { if ($.inArray('myAltRowClass', className.split(' ')) === -1) { row.className = className + ' myAltRowClass'; } } } } } </code></pre> <p>The corresponding demo is <a href="http://www.ok-soft-gmbh.com/jqGrid/SimpleLocalGridChangeRowBackgroundBasedOnCheckboxes.htm" rel="nofollow noreferrer">here</a>. You will see the following:</p> <p><img src="https://i.stack.imgur.com/cg6RJ.png" alt="enter image description here"></p> <p>By the way if the 'Closed' column will be hidden everything will continue to work as before.</p> <p><strong>UPDATED 2</strong>: <a href="https://stackoverflow.com/a/10531680/315935">The answer</a> describe how to use <code>rowattr</code> callback to simplify the solution and to have the best performance (in case of <code>gridview: true</code>).</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. VO
      singulars
      1. This table or related slice is empty.
    2. VO
      singulars
      1. This table or related slice is empty.
    3. VO
      singulars
      1. This table or related slice is empty.
 

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