Angular datatables with filter column width
Asked Answered
P

3

6

I tried to set width for column in angular datatables with filters. But width of the column not changed.

I try following

   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']);

In html file I tried this:

   <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>

But Value column another zise rather I setted.

I'v found, that if there is not filter - all fine.

How can I set table width and preserve filters?

Preordain answered 8/9, 2015 at 19:55 Comment(3)
Try adding .withOption('autoWidth', false).Rivi
I'v tryed it, it still not working.Preordain
For me neither, is there a bug in the new version?Incorrupt
H
9
vm.dtColumns = [
        DTColumnBuilder.newColumn('id').withTitle('ID').withOption('width', '5%')
    ];
Helm answered 26/5, 2016 at 13:43 Comment(0)
Y
0

You need to define the option width in your columnDefs option:

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

See this example.

Yamada answered 9/9, 2015 at 15:27 Comment(0)
D
0

Finally I've found the solution for avoiding datatables overwrite bootstrap columns width definitions:

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

It was as easy as put that name and set to false... but it in the API doesn't appear to be available :(

Deanndeanna answered 18/1, 2018 at 9:29 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.