开发者

How to apply rows style depending on cell data with jqgrid?

开发者 https://www.devze.com 2022-12-15 19:35 出处:网络
My use case is the following: Having a table like: +------------------------------+ NOTICE| This is notice #1|

My use case is the following:

Having a table like:

+------------------------------+
| NOTICE  | This is notice #1  |
| WARNING | This is warning #1 |
| NOTICE  | This is notice #2  |
| ERROR   | This is error  #1  |
+------------------------------+

I'd like to have a specific background color for the whole rows depending of the value of first column.

To implement this, I'd like to make use of a class applied on the row so that I can skin it easily with:

tr.NOTICE t开发者_如何学编程d {background-color: Yellow}
tr.WARNING td {background-color: Orange}
tr.ERROR td {background-color: OrangeRed}

Not sure it is possible with jqGrid, maybe with a Custom Formatter? No idea how

Thanks in advance


This works for me:

afterInsertRow:function(rowid, rowdata, rowelem){
  var status = rowdata['status']; 
  if(status=='0'){
   $("tr.jqgrow#"+rowid).addClass("ui-state-error"); 
  }
}


Found a way to do it:

$("#myGrid").jqGrid({
    ...
    gridComplete: function() {
    var _rows = $(".jqgrow");
    for (var i = 0; i < _rows.length; i++) {
      _rows[i].attributes["class"].value += " " + _rows[i].childNodes[0].textContent;
    }
});0
0

精彩评论

暂无评论...
验证码 换一张
取 消