简体   繁体   English

jQuery Datatable根据值更改行颜色

[英]Jquery Datatable change row color based on value

I have this jquery datatable below. 我下面有这个jQuery数据表。 If id is 50415, I want row color to change to red. 如果id为50415,我希望行颜色更改为红色。 but it fails to do despite adding the css. 但是,尽管添加了css,它仍然无法执行。 Tried many of the soloutions on stackoverflow. 在stackoverflow上尝试了许多解决方案。 Do advise, thanks so much. 请多多指教,非常感谢。

{
  "mDataProp": null,
  render: function (data, type, row, i) {
    var reconJrnlId = (data.jrnlItemId).toString();                 
    if (reconJrnlId === '50415') {
      console.log('change to red please');
      $(row).css("background-color","red");
    }                   
    return '-';
  }

I'm not too sure how your data is structured. 我不太确定您的data的结构。 But you can get the key of the data and check if the key value is your id. 但是您可以获取数据的密钥,并检查密钥值是否是您的ID。 So then you can add the CSS this way 所以你可以这样添加CSS

var id = data[3];
   if(id == 66){
   console.log(data);
   $(row).addClass('blue');   //add class to row
   }

See fiddle here https://jsfiddle.net/d9m6bzyg/1/ You will see row number 2 in blue ie Ashton Cox 在这里查看小提琴https://jsfiddle.net/d9m6bzyg/1/您将看到蓝色的第2行,即Ashton Cox

This example was take from here http://live.datatables.net/cezewiqe/1/edit 此示例来自此处http://live.datatables.net/cezewiqe/1/edit

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM