【发布时间】:2020-01-14 01:09:24
【问题描述】:
我正在使用数据表,并且遇到了数据表对列大小的响应性问题。
当数据表被定义为列的大小时,即更大并且表的最后一列不显示。
所以我尝试添加一个带有max-width 的 CSS 类,但它不起作用。
HTML:
<script src="https://cdn.datatables.net/1.10.19/js/jquery.dataTables.js"></script>
<script src="https://cdn.datatables.net/responsive/2.2.3/js/dataTables.responsive.min.js"></script>
<table class = "display" id = "datatable"></table>
CSS:
.cell_table {
max-width: 250px;
}
JS:
$('#datatable').DataTable({
"sPaginationType" : "full_numbers",
"columnDefs" : [{
"targets": "_all",
"createdCell" : function (td, cellData, rowData, row, col) {
$(td).attr('id', 'cell-' + col);
},
}, {
"targets" : [0, 1, 2, 3],
"className" : "text_center cell_table",
}],
"lengthMenu" : [[5, 10, 20, 30, -1], [5, 10, 20, 30, "All"]],
"iDisplayLength" : -1,
data : data_use,
columns : column_name,
dom : 'lfrtip',
responsive : true,
destroy : true,
searching: true,
});
Here你可以在JSfiddle上找到代码。
【问题讨论】:
标签: javascript css datatables