admin管理员组文章数量:1356284
I have a table that is empty until the user do some actions. The problem is that when the table is empty, the column have one width and when the table has content (some inputs on td
) the width changes. What i want is to keep the column size fixed, that is, the same column size when the table is empty and when it has content.
The following code shows de Datatable configuration. That widths shown are what i need but, for example, when the table is empty, the first column has width
of 114px
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"},
]
});
I have a table that is empty until the user do some actions. The problem is that when the table is empty, the column have one width and when the table has content (some inputs on td
) the width changes. What i want is to keep the column size fixed, that is, the same column size when the table is empty and when it has content.
The following code shows de Datatable configuration. That widths shown are what i need but, for example, when the table is empty, the first column has width
of 114px
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"},
]
});
Share
Improve this question
asked Aug 12, 2014 at 12:22
Fernando PrietoFernando Prieto
5201 gold badge6 silver badges20 bronze badges
2
-
Try putting
sScrollX: "100%",
as datatable paramter – Bhushan Kawadkar Commented Aug 12, 2014 at 12:35 - assign any one columns width as auto. – Suresh Ponnukalai Commented Aug 12, 2014 at 12:37
3 Answers
Reset to default 2I SOLVED THE PROBLEM just adding divs on th
width fixed widths.
In the table definition i had this HTML
with the Datatable
configuration shown on the question:
<thead>
<tr>
<th>Code</th>
</tr>
<tr>
<th>Description</th>
</tr>
</thead>
What i did now, is to add divs on the HTML:
<thead>
<tr>
<th><div style="width: 100px;">Codigo</div></th>
</tr>
<tr>
<th><div style="width: 300px;">Description</div></th>
</tr>
</thead>
And the current Datatable configuration is:
tabla = $('#tabla').DataTable({
language: {
url: '/recursos/estilos/DataTables-1.10.1/js/locale/es_AR.json'
},
"bSort": false
});
- set autoWidth: false;
- set px values to first 3 columns; important: check if the table width is a bit more than 3 columns + final one;
adjust the table width and 4th column.
$('#example').DataTable({ //four column table autoWidth: false, //step 1 columnDefs: [ { width: '300px', targets: 0 }, //step 2, column 1 out of 4 { width: '300px', targets: 1 }, //step 2, column 2 out of 4 { width: '300px', targets: 2 } //step 2, column 3 out of 4 ] });
Specifying a fixed column width in jQuery Datatables
you can define a CSS class to your column like this :
aoColumns : [ { "sClass": "my_class" }]
And in your CSS :
.my_class
{
overflow:hidden;
width:200px;
}
本文标签: javascriptFixed column width on DatatablesStack Overflow
版权声明:本文标题:javascript - Fixed column width on Datatables - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1743975282a2570853.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论