Highlight cell based on column name

Highlight cell based on column name

babablacksheepbabablacksheep Posts: 41Questions: 23Answers: 0
edited February 2016 in Free community support

This is my sample data for individual row

{
    id: 12,
    name: 'Fred',
    highlight: ['name'] // highlight column with name key
}

Highlight key indicated which key to highlight, in this case name column.

PROBLEM: I know i can use rowCallBack and manipulate cells there but I cant seem to figure out how can i find cell`s column name so I can highlight it.

OBJECTIVE: How do I find each cell`s column name so I can check if it exists in highlight array then add highlight class red

JSFIDDLE: https://jsfiddle.net/bababalcksheep/oLjy0rmL/

$(document).ready(function() {
  //
  var data = [{
    id: 12,
    name: 'Fred',
    highlight: ['name'] // highlight column with name key
  }, {
    id: 13,
    name: 'Simon',
    highlight: []
  }, {
    id: 14,
    name: 'Albert',
    highlight: ['name']
  }];
  //
  var table = $('#example').DataTable({
    "columns": [{
      'title': 'ID',
      'data': 'id',
      'name': 'id',
    }, {
      'title': 'Name',
      'data': 'name',
      'name': 'name',
    }],
    data: data,
    rowCallback: function(row, data, index) {
      var _hasHighlight = data.highlight && data.highlight.length;
      if (_hasHighlight) {
        $(row).find('td').each(function() {
          //how do I find each cell`s column name so i can check
          //if it exists in _hasHighlight array then add highlight class red 
        });
      }
    }
  });

});
This discussion has been closed.