【发布时间】:2018-01-05 07:29:50
【问题描述】:
版本:AngularJS 1.6.4,angular-datatables 0.5.6
问题:无法使用
更改列宽.withOption('width', '20%')
我浏览了大部分 SO 问题,但仍未找到答案。
这是我的示例代码:
JS:
$scope.dtOptions = DTOptionsBuilder.newOptions()
.withOption('paging', false)
.withOption('bInfo', false)
.withOption('searching', false)
.withScroller().withOption('scrollY', 300)
.withOption('responsive', true)
.withOption('scrollX', true)
.withOption('scrollCollapse', true)
.withOption("rowCallback", rowCallback)
.withOption('autoWidth', true);
$scope.dtColumnDefs = [
DTColumnDefBuilder.newColumnDef(0).notSortable(),
DTColumnDefBuilder.newColumnDef(1).notSortable(),
DTColumnDefBuilder.newColumnDef(2),
DTColumnDefBuilder.newColumnDef(3),
DTColumnDefBuilder.newColumnDef(4),
DTColumnDefBuilder.newColumnDef(5).notSortable(),
DTColumnDefBuilder.newColumnDef(6).notSortable(),
DTColumnDefBuilder.newColumnDef(7).notSortable(),
DTColumnDefBuilder.newColumnDef(8).notSortable().withOption('width', '20%'),
DTColumnDefBuilder.newColumnDef(9).notSortable(),
DTColumnDefBuilder.newColumnDef(10).notSortable(),
DTColumnDefBuilder.newColumnDef(11).notSortable(),
DTColumnDefBuilder.newColumnDef(12).notSortable(),
DTColumnDefBuilder.newColumnDef(13).notSortable()
];
HTML:
<table datatable="ng" dt-options="dtOptions" dt-column-defs="dtColumnDefs" class="hover">
<thead>
<tr>
<th><!--14 headers here--></th>
</tr>
</thead>
<tbody>
<tr>
<td><!--14 data cells here--></td>
</tr>
</tbody>
</table>
我已经确认大多数 dtOptions withOption 工作正常,除了
.withOption('autoWidth', true);
在 dtColumnDefBuilder 中,
.notSortable()
工作正常,但不是
.withOption('width','20%')
我尝试过的事情:
- 设置表格标题的内联样式宽度
- 注释掉 dtOptions .withOption() 来检查
感谢您的帮助
【问题讨论】:
标签: angularjs datatables width angular-datatables