【问题标题】:Databases columns-width function is not working数据库列宽功能不起作用
【发布时间】:2016-09-07 03:44:40
【问题描述】:

我正在尝试使用响应式数据表归档固定列宽 https://datatables.net/reference/option/columns.width

$('#example').dataTable( {
"columnDefs": [
{ "width": "20%", "targets": 0 }
]
} );

但如果列文本比用like ("width": "20%") 指定的要大,它会自动调整列宽。 如何将其限制为适合列宽并使用省略号修剪多余的部分?

【问题讨论】:

  • 设置 autoWidth: false 并记住声明所有列的宽度以免感到惊讶。
  • 你能给我们一个例子,然后我可以给你一个修复。

标签: html twitter-bootstrap datatables


【解决方案1】:

请将此 css 添加到您的数据表 width: 100% !important;word-wrap: break-word;它将为您工作。

<script>

     $('#example').dataTable( {
        "columnDefs": [
        { "width": "20%", "targets": [0] }],
           fixedColumns: true
        } );

</script>

.customDataTableLayout {
    width: 100% !important;
    word-wrap: break-word;
}

例如

 <table class="customDataTableLayout" width="100%">
       <thead>
         <tr>
         <th>ID</th>
         <th>student name</th>
         <th>student Code</th>
         <th>Status</th>
         </tr>
        </thead>
     </table>

【讨论】:

  • 您声明.customDataTableLayout 但引用#companyDataTable - 这应该如何工作?在 CSS 中同时使用 width: 100% !important; 和 width="100%" 作为元素属性有什么意义?
猜你喜欢
  • 2023-03-12
  • 1970-01-01
  • 1970-01-01
  • 2020-03-16
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2013-03-10
  • 1970-01-01
相关资源
最近更新 更多