2015-10-17 58 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