我正在以角度方式渲染DataTable-请参见下面的示例表。
<table id="tblSamples" datatable="ng" dt-options="mainCtrl.dtOptions" dt-instance="mainCtrl.dtInstance" class="table table-responsive table-hover">
<thead>
<tr>
<th>Number</th>
<th>Source</th>
<th>Type</th>
<th>SubCat</th>
<th>Product</th>
<th>Applied Amount</th>
<th>Sample Amount</th>
<th><input type="checkbox" ng-model="mainCtrl.selectAll" ng-click="mainCtrl.toggleAll(mainCtrl.selectAll, mainCtrl.Samples)"></th>
</tr>
</thead>
<tbody>
<tr ng-repeat="sampleItem in mainCtrl.Samples">
<td ng-if="sampleItem.TTTId != null"><a title="View {{sampleItem.TTT.Number}}" href="/TTT/Details/{{sampleItem.TTTId}}"><u>{{sampleItem.TTT.Number}}</u></a></td>
<td ng-if="sampleItem.PPPId != null"><a title="View {{sampleItem.PPP.Number}}" href="/PPP/Details/{{sampleItem.PPPId}}"><u>{{sampleItem.PPP.Number}}</u></a></td>
<td ng-if="sampleItem.MMMId != null"><a title="View {{sampleItem.MMM.Number}}" href="/MMM/Details/{{sampleItem.MMMId}}"><u> {{sampleItem.MMM.Number}}</u></a></td>
<td ng-if="sampleItem.LLLId != null"><a title="View {{sampleItem.LLL.Number}}" href="/LLL/Details/{{sampleItem.LLLId}}"><u>{{sampleItem.LLL.Number}}</u></a></td>
<td>{{sampleItem.Type.Source.Name}}</td>
<td>{{sampleItem.Type.Name}}</td>
<td ng-if="sampleItem.SubCatId != null">{{sampleItem.SubCat.Name}}</td>
<td ng-if="sampleItem.SubCatId == null"></td>
<td ng-if="sampleItem.ProductId != null">{{sampleItem.Product.Name}}</td>
<td ng-if="sampleItem.ProductId == null"></td>
<td>{{sampleItem.Amount}}</td>
<td ng-disabled="sampleItem.ForAdd != true"><input type="number" id="SampleAmount" name="SampleAmount" class="form-control ng-pristine ng-untouched ng-valid ng-not-empty" ng-model="sampleItem.SampleAmount" min="0" required /></td>
<td><input type="checkbox" ng-model="sampleItem.ForAdd" ng-click="mainCtrl.toggleOne(mainCtrl.Samples)"></td>
</tr>
</tbody>
</table>
在角度控制器中定义列时,如何像下面的代码一样将列设置为不可排序
DTColumnBuilder
.newColumn(null)
.withTitle('Actions')
.notSortable()
.renderWith(actionsHtml)
答案 0 :(得分:1)
查看 http://l-lin.github.io/angular-datatables/archives/#!/angularWayWithOptions
包含columns
和索引columnDefs
的{{1}}代替了targets
:
<table id="tblSamples" datatable="ng" dt-column-defs="dtColumnDefs" ....>
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(1).notSortable()
]
索引基于零,因此第二列将无法排序。我通常避免使用“ builders”,而只需使用
$scope.dtColumnDefs = [{
targets: 1,
orderable: false
}]
如果您禁用第一列的排序,您仍将看到一个排序箭头,因为默认顺序为[[0, 'asc']]
。您可以在dtOptions
中通过
.withOption('order', [])