How to apply style to the Jquery datatable column depending on the column value

前端 未结 2 1452
独厮守ぢ
独厮守ぢ 2021-01-28 01:07

http://jsfiddle.net/ktdj3u9r/5/

I am uisng Jquery DataTable to display data in a Tabular format .

My requirement is that if the quantity field is greater than 1

相关标签:
2条回答
  • 2021-01-28 01:49

    Use the createdCell callback in yor quantity declaration :

    ...
    "columns": [
         { "title": "Name" },
         { "title": "Price" },
         { "title": "Quantity" ,
            mRender: function(data, type, row){
               var quantity = row[2] ;
               return quantity;
            },
            createdCell: function (td, cellData, rowData, row, col) {
               if (cellData>100000) $(td).css('color', 'green');
            }
         }
    ]
    ...
    

    forked fiddle -> http://jsfiddle.net/5fbo72rm/

    0 讨论(0)
  • 2021-01-28 01:49

    Use fnRowCallback for this:

    "fnRowCallback": function (nRow, aData, iDisplayIndex, iDisplayIndexFull) {
             if(aData[2] > 100000){
                 $('td:eq(2)', nRow).addClass("td-green");
             }
      }
    

    This will add the class td-green to any value > 100000

    updated fiddle: https://jsfiddle.net/markps/ktdj3u9r/6/

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