It's interesting question! In general rowattr
callback is the best way to assign attributes (for example class attribute) to the rows, but rowattr
callback in the current implementation of jqGrid has no information about the index of the row. So one have to set altclass
inside of loadComplete
.
To set standard altclass
one can use the following
loadComplete: function () {
$(this).find(">tbody>tr.jqgrow:visible:odd").addClass("myAltRowClass");
}
You can use the code in case of alternating TreeGrid (see the answer) or Grouping for example.
If you need to alternate every-two-rows then you can use custom filter instead of :odd
. For example the demo uses
loadComplete: function () {
$(this).find(">tbody>tr.jqgrow:visible")
.filter(function (i) {
return i % 4 >= 2;
})
.addClass("myAltRowClass");
}
and it displays the following grid