How do you change background of specific cell in a JQuery.DataTable?

后端 未结 1 1040
北荒
北荒 2020-12-12 00:39

I\'m trying to change the styling of some specific cells in a DattaTable, but I\'m not sure how to do that. I know how to change for an entire column, but that\'s not what i

相关标签:
1条回答
  • 2020-12-12 01:11

    You would use the column configuration's createdCell function.

    Basically, you need to add a column definition for the gender column that includes a callback that will be called when the cell is populated. Try adding this object to your columns array:

        {
          data: "gender",
          createdCell: function(td, cellData, rowData, row, col){
            var color = (cellData === 'm') ? 'blue' : 'red';
            $(td).css('color', color);
          }
        }
    

    Here is a working example.

    0 讨论(0)
提交回复
热议问题