简体   繁体   English

使用数据表比较两列

[英]compare two columns using datatables

My goal is to highlight a row if two columns contain the same string within a row using datatables I am not sure how would I compare two columns. 我的目标是使用数据表突出显示一行中是否两列包含相同字符串的行,我不确定如何比较两列。 I want to do something like this. 我想做这样的事情。 This is part of my code 这是我的代码的一部分

  "columnDefs":[
  {
      "targets":[3,4], 
      "render": function ( data, type, full, meta ) { 
       if value of 3 = 4 {
         //highlight the row
       }
      }
   } ],

Thanks in advance. 提前致谢。

SOLUTION

Use rowCallback option to define a callback function that will be called when row would be drawn. 使用rowCallback选项定义将在绘制行时调用的回调函数。

$('#example').dataTable({
  "rowCallback": function(row, data, index){
    if (data[3] === data[4]) {
       $(row).addClass('selected');
    }
  }
});

DEMO 演示

See this jsFiddle for code and demonstration. 有关代码和演示,请参见此jsFiddle

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

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