javascript - 固定数据表上的列宽

标签 javascript jquery html css datatables

我有一个空表,直到用户执行某些操作。问题是,当表格为空时,列只有一个宽度,而当表格有内容(td 上的一些输入)时,宽度会改变。我想要的是保持列大小固定,即当表为空时和有内容时列大小相同。

以下代码显示了数据表配置。显示的宽度是我需要的,但是,例如,当表格为空时,第一列的 width114px

tabla = $('#tabla').DataTable({
    language: {
        url: '/recursos/estilos/DataTables-1.10.1/js/locale/es_AR.json'
    },          
    "bSort": false,
    "bAutoWidth": false,
     aoColumns : [
      { "sWidth": "104px"},
      { "sWidth": "263px"},
      { "sWidth": "105px"},
      { "sWidth": "105px"},
      { "sWidth": "105px"},
      { "sWidth": "105px"},
      { "sWidth": "33px"},
    ]
}); 

最佳答案

解决了这个问题只是在th 宽度固定宽度上添加div。

在表定义中,我有这个 HTML 和问题上显示的 Datatable 配置:

<thead>
    <tr>                            
        <th>Code</th>
    </tr>
    <tr>                            
        <th>Description</th>
    </tr>
</thead>

我现在所做的是在 HTML 上添加 div:

<thead>
    <tr>                            
        <th><div style="width: 100px;">Codigo</div></th>
    </tr>
    <tr>                            
        <th><div style="width: 300px;">Description</div></th>
    </tr>
</thead>

当前Datatable配置为:

tabla = $('#tabla').DataTable({
    language: {
        url: '/recursos/estilos/DataTables-1.10.1/js/locale/es_AR.json'
    },          
    "bSort": false
});

关于javascript - 固定数据表上的列宽,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25264209/

相关文章:

javascript - 根据内部内容调整所有文本区域的大小

javascript - 任何人都知道使用 Raphael 生成的良好条形图的示例吗?

javascript - react native : How to pass parameter to gesture responder callback

javascript - 无法将 html 连接到 css

jquery - 如何添加无序列表元素符号

jquery - 将表格单元格宽度设置为祖先的百分比而不影响相邻单元格宽度

jquery - 动态添加 DOM 元素后,轨道 slider 无法设置动画

html - 带有选择和清除图标的 Bootstrap 搜索框

html - 如何在 PhoneGap 中添加自定义字体

jquery - Raphael.js 如何在 Raphael.js 中使用 CSS 文件?