【发布时间】:2021-12-22 16:53:45
【问题描述】:
我想手动调整表格列的大小。
在 Stack Overflow 上搜索并尝试过
How to make columns of datatables.js resizable with jQuery UI & jQuery UI Resize with table and colspans
还有google例子,官方文档。
https://github.com/dobtco/jquery-resizable-columns & http://jsfiddle.net/Twisty/ah67jopf/3/
我的示例代码
<table id="examTbl" class="table table-bordered table-hover table-sm dataTable dtr-inline" data-resizable="true">
<thead>
<tr>
<th><input type="checkbox" id="chkbox"></th>
<th>1</th>
<th>2</th>
</tr>
</thead>
</table>
<style>
table, td, th {
/*table-layout:fixed;*/
overflow:hidden;
white-space: nowrap;
text-overflow: ellipsis;
}
</style>
数据表设置
var table_option = {
processing: true,
serverSide: true,
searching: false,
responsive: true,
dom: "lfBtip",
ajax: {
url: '/get/textVal'
},
columns: [{
data: 'null',
defaultContent: "<input type='checkbox' class='chkbox'>",
},
{ data: 'test1' },
{ data: 'test2' },
],
autoWidth: false,
drawCallback: function(settings) {
$('table th').resizable({
handles: 'e',
minWidth: 18,
stop: function(e, ui) {
$(this).width(ui.size.width);
}
});
}
}
【问题讨论】:
-
控制台没有错误。
标签: javascript jquery node.js datatables resizable