2015-10-17 71 views
1

如何在數據值爲true時修改td類的當前數據?如何修改當前td節點類

目前我只顯示一個空值,但更新td類會顯示一個圖標。如下所示

columnDefs: [ 
    { targets: [ 1], visible: false, searchable: false }, 
    { 
     targets: [ 3], 
     render: function (data, type, full, meta) { 
     if(type === 'display') { 
      if(data==true){ 
       // add class 'details-secret' to current node td 
       return ""; 
      } 
     } 

     return data; 
     } 
    }, 

回答

2
使用

選項createdCell

columnDefs: [ 
    { targets: 1, visible: false, searchable: false }, 
    { 
     targets: 3, 
     createdCell: function(cell, data, index){ 
     if(data == true){ 
      $(cell).addClass('details-secret'); 
     } 
     } 
    }, 
    // ... skipped ... 

參見this example用類似的方法createdRow