tags:

views:

579

answers:

3

how can i add alternate background row in jqgrid?

A: 

Here's how you do it:

$("#myGrid").jqGrid({
   ...
   gridComplete: function() {
       var _rows = $(".jqgrow");
       for (var i = 0; i < _rows.length; i += 2) {
           _rows[i].attributes["class"].value += " alt";
       }
   }
});
Ngu Soon Hui
*Way* too much work. This feature is already built into the grid. No need to reinvent it.
Craig Stuntz
+2  A: 

Look at the altRows and altclass options. Beware of the typically inconsistent capitalization!

Craig Stuntz
A: 

if you need to perform this dynamically (like when using the sortableRows functionality) you can call these two lines to reset the alternate color based on the jQueryUI css scheme:

$('#'+gridName+' tr:nth-child(even)').removeClass("ui-priority-secondary");
$('#'+gridName+' tr:nth-child(odd)').addClass("ui-priority-secondary");
Pete Amundson