6

我尝试使用过滤器为角度数据表中的列设置宽度。但是列的宽度没有改变。

我尝试关注

   var columnsSpecification = [
      {
          type: 'text',
          bRegex: true,
          bSmart: true
      }, {
          type: 'text',
          bRegex: true,
          sWidth:"90px"}];


    $scope.dtOptions = DTOptionsBuilder.newOptions()
      .withBootstrap()
      .withOption('scrollX', '700%')
      .withOption('scrollY', height + 'px')
      .withOption('oLanguage', { "sEmptyTable": " " })
      .withOption('lengthMenu', [[-1, 1000, 100, 50, 25, 10], ['All', 1000, 100, 50, 25, 10]])
      .withOption('paging', false)
      .withOption('bInfo',false)
      .withColumnFilter({          
      aoColumns:columnsSpecification 
  })
  .withTableTools('/Content/DataTables/swf/copy_csv_xls.swf')
  .withTableToolsButtons(['xls']);

在 html 文件中,我尝试了这个:

   <table id="table-machines" datatable="ng" class="table table-striped" dt-options="dtOptions">
    <thead>
        <tr>
            <th>Name</th>
            <th style="width: 90px !important">Value</th>                
        </tr>
    </thead>
    <tbody>
        <tr ng-repeat="m in records>
            <td>{{m.name}}</td>
            <td style="width: 90px !important">{{m.Value}}</td>                
        </tr>
    </tbody>

但是我设置了另一个值列。

我发现,如果没有过滤器 - 一切都很好。

如何设置表格宽度并保留过滤器?

4

3 回答 3

9
vm.dtColumns = [
        DTColumnBuilder.newColumn('id').withTitle('ID').withOption('width', '5%')
    ];
于 2016-05-26T13:43:35.500 回答
0

您需要在选项width中定义columnDefs选项:

vm.dtColumnDefs = [
    DTColumnBuilder.newColumn(1).withOption('width', '90px')
  ];

请参阅此示例

于 2015-09-09T15:27:24.830 回答
0

最后我找到了避免数据表覆盖引导列宽度定义的解决方案:

$scope.dtOptions = DTOptionsBuilder.newOptions()
    .withOption('autoWidth', false)

就像输入该名称并设置为 false 一样简单......但它在 API 中似乎不可用:(

于 2018-01-18T09:29:30.957 回答