简体   繁体   中英

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.

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

DEMO

See this jsFiddle for code and demonstration.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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