首页 > 解决方案 > Angularjs Datatable 从列可见性中排除列

问题描述

我正在研究数据表列的可见性,但我不希望所有表列都显示在可见性下拉列表中,只需要显示几个

我试过 DTColumnDefBuilder.newColumnDef(0).withTitle('Name').notVisble() 但它删除了列并没有解决它

html代码

<table class="table table-striped  dataTable no-footer dtr-inline" datatable="ng" dt-options="dataDtOptions" dt-instance="dataDtInstance"  width="100%"  dt-columns="dataDtColumns" dt-column-defs="dataDtColumnDefs">
<thead>
<tr>
<th>column1</th>                            
<th>column2</th>                                 
<th>column3</th>                                    
<th>column4</th>                                                                         
<th>column5</th>                                    
<th>column6</th>                                    
</tr>
</thead>
<tbody>
<tr style="cursor:pointer"  ng-repeat="data  in datas" >
<td>{{data[0]}}</td>
<td>{{data[1]}}</td>
<td>{{data[2]}}</td>
<td>{{data[3]}}</td>
<td>{{data[5]}}</td>
<td>{{data[6]}}</td>
 </tr>
</tbody> 
 </table>

angulajs 代码

$scope.dataDtOptions = DTOptionsBuilder.newOptions()
.withDOM("<'row'<'col-sm-5'l><'col-sm-2 width-200 pull-right'B><'col-sm-5 pull-right'f>>" +"<'row'<'col-md-12't>>" +"<'row'<'col-sm-5'i><'col-sm-7'p>>")
.withPaginationType('full_numbers')
.withButtons([
    'colvis',
     {
        extend: 'collection',
        text: 'Export',
        buttons: [
            'csv',
            'pdf'
        ]
    }
]);

$scope.dataDtColumnDefs = [
 DTColumnDefBuilder.newColumnDef(0).withTitle('column1'),
 DTColumnDefBuilder.newColumnDef(1).withTitle('column2'),
 DTColumnDefBuilder.newColumnDef(2).withTitle('column3'),
 DTColumnDefBuilder.newColumnDef(3).withTitle('column4'),
 DTColumnDefBuilder.newColumnDef(4).withTitle('column5'),
 DTColumnDefBuilder.newColumnDef(5).withTitle('column6'),
 ]

所以我不希望列可见性下拉列表中的第一列和最后一列

标签: angularjsdatatablesangular-datatables

解决方案


You can do the following:

DTColumnBuilder.newColumnDef(0).withClass('hidden')

And in CSS if you don't already have bootstrap installed

.hidden { display: none; }


推荐阅读