English 中文(简体)
jqGrid row alternating background
原标题:

How can I insert alternating row background color in jqGrid?

问题回答

Look at the altRows and altclass options. Beware of the typically inconsistent capitalization! This does use the jQuery UI theme if you re using jqGrid 3.5 or higher.

To use the jQuery UI theme use this code:

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

I use this code when I perform manual sorting (drag-n-drop)

function applyZebra(containerId) {
    $( #  + containerId +   tr:nth-child(even) ).addClass("jqgrow evenTableRow");
    $( #  + containerId +   tr:nth-child(odd) ).addClass("jqgrow oddTableRow");
}

ContainerId is your jqGrid ID. Call this method on the "gridComplete" event of your jqGrid.

Hello first defines the css:

<style type="text/css"> 
......
.Color_Red { background:red; }
.Color_Cyan { background:cyan; } 
......

Then in jqGrid ...

$("#list2").jqGrid({
........
loadComplete: function() {
  var rowIDs = jQuery("#list2").getDataIDs(); 
  for (var i=0;i<rowIDs.length;i=i+1){ 
    rowData=jQuery("#list2").getRowData(rowIDs[i]);
    var trElement = jQuery("#"+ rowIDs[i],jQuery( #list2 ));

// Red       
    if (rowData.Estado == 0) {
        trElement.removeClass( ui-widget-content );
        trElement.addClass( Color_Red );
    }

// Cyan        
    if (rowData.Estado == 2) {
        trElement.removeClass( ui-widget-content );
        trElement.addClass( Color_Cyan );
    }
}
},

});

Thus we walk the rows and apply RED to fulfill the condition that == 0 and Cyan which satisfy the condition == 2.

You should change rowData.XXX == XX by column name and value to check.

I have it this way and it works perfectly.

Luck!

Call loadComplete function to change background color of row in jqgrid.

loadComplete : function() {
    $("tr.jqgrow:odd").addClass( myAltRowClassEven );
    $("tr.jqgrow:even").addClass( myAltRowClassOdd );
},

for applying styles to background use below css.

<style type="text/css">
.myAltRowClassEven { background: #E0E0E0; border-color: #79B7E7; }
.myAltRowClassOdd { background: orange; }
</style>

Or

For changing row font in jqgrid see click below link

How can I change Background colour and Font of any row in JQGrid?

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";
       }
   }
});




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签