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

ant*_*wrx 6 javascript datatables

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

我的HTML是:

<table class="table table-striped table-bordered table-hover" id="id-table" width="100%"></table>
Run Code Online (Sandbox Code Playgroud)

我将表实例化为:

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
        }
    );
Run Code Online (Sandbox Code Playgroud)

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

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

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

Ama*_*the 8

在你的HTML表格标记设置样式table-layout'fixed',并通过bAutoWidth = false对数据表功能