jQuery数据表 - 隐藏列样式

时间:2018-02-23 22:22:51

标签: jquery ajax datatables

我的MVC应用程序中有一个AJAX DataTable,其中每一行都有一个相关的图标,用于确定该行是否需要特别注意:

enter image description here

但是,我想删除该列上的列样式,如下所示:

enter image description here

你知道如何做到这一点,最好是在AJAX Datatables方法中吗?

1 个答案:

答案 0 :(得分:1)

您可以使用createdRow选项根据行数据向需要特别关注的每一行添加类。

例如:

var table = $('#example').DataTable({
   "createdRow": function( row, data, dataIndex ) {
      if(data[2] === 'London'){
         $(row).addClass('warning');
      }
   }
});

然后您可以使用CSS根据需要设置该行的样式。

使用以下样式可以实现您的要求:

.dataTables_wrapper {
  padding-right: 30px;
}

tr.warning td:last-child {
  position: relative;
}

tr.warning td:last-child:after {
  position: absolute;
  right: -30px;
  content: '(!)';
  color: red;  
}

请参阅this example以获取代码和演示。

但是我建议使用背景颜色来突出显示行,我认为它不那么具有侵入性,并且不需要!图标的空间。有关代码和演示,请参阅this example