数据表:过滤后禁用列大小调整

时间:2015-06-08 10:23:06

标签: javascript datatables

我正在使用数据表,我使用javascript填充数据表。它工作正常,但我想防止数据在过滤后调整表的列宽。我尝试过在网上找到的几种解决方案,但它似乎无法解决问题。

我的HTML是:

<table class="table table-striped table-bordered table-hover" id="id-table" width="100%"></table>

我将表格实例化为:

var table = $('#id-table').DataTable(
        {
            paging:     false,
            ordering:   false,
            info:       false,
            "bAutoWidth": false, // Disable the auto width calculation : false,
            columns:  columns,
            data :    assignments,
            sScrollX: "100%",
            // aoColumns :  aoColumns
  //           aoColumns : [ 
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" },
  //   { "sWidth": "150px" }
  // ]

            // aoColumns: aoColumns
           // columnDefs : cdefs
        }
    );

其中data是一个数组,数据和列是一个对象数组,如:

bSearchable false
sTitle "Column Title"
sWidth "100px"
title "Column Title"
mRender function(data, type, full, meta)
render function(data, type, full, meta)

我尝试直接在两个“列”中设置宽度并使用“aoColumns”选项(在上面的代码中注释掉)。在这两种情况下,过滤后列宽仍会调整大小。关于如何禁用此自动调整大小的任何想法?

2 个答案:

答案 0 :(得分:7)

在你的html表标签中设置样式table-layout'fixed'并将bAutoWidth = false传递给datatable函数

答案 1 :(得分:0)

我在当前版本的DataTables(v1.10.16)中遇到了这个问题,因为我将autoWidth设置为false而不理解它的作用。

在默认配置(CSS table-layout: auto + DataTables&#39; autoWidth: true)中,根据数据对列进行适当调整,并在过滤时不跳转。

相关问题