【问题标题】:How to set max-width for particular column in jQuery DataTables如何在 jQuery DataTables 中为特定列设置最大宽度
【发布时间】:2016-03-03 05:13:38
【问题描述】:

如何为一个特定列设置最大宽度,所有其他列都应自动调整大小。我试过下面的代码,但它不起作用,因为我认为没有'max-width'属性

$('#table').dataTable({
    'paging': false,
    'info': false,
    'searching': false,
    'columnDefs': [
      {'max-width': '320px', 'targets': 'my-column'}
    ],
});

【问题讨论】:

  • 你能检查一下我的答案吗?
  • max-width 对我不起作用。 targets 也可以是列的 css 类,而不仅仅是索引
  • 不需要在目标选项中提及类名,只需提及列的位置编号,我用我的项目进行测试,效果很好
  • 为什么不使用数据表中字段的索引?

标签: jquery datatable


【解决方案1】:

试试这样的

最大宽度选项提及宽度百分比

targets选项提及字段索引

$('#table').dataTable({
    'paging': false,
    'info': false,
    'searching': false,
    'columnDefs': [
      {'max-width': '20%', 'targets': 0}
    ],
});

【讨论】:

  • 我不认为 columnDefs 包含 'max-width' 属性,所以这可能不起作用...datatables.net/reference/option/columnDefs
  • 正如@Bartosz 提到的,我看不到任何最大宽度选项。如果它存在于任何版本中,请标记该版本。
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2014-05-28
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多