我正在使用 jQuery 的DataTables插件,我想在加载数据后重新排序列。我知道我可以在创建表格时重新排序它们。
我想做的是绘制表格,从服务器加载数据,然后根据服务器的响应对列进行重新排序。
我怎样才能做到这一点?
我正在使用 jQuery 的DataTables插件,我想在加载数据后重新排序列。我知道我可以在创建表格时重新排序它们。
我想做的是绘制表格,从服务器加载数据,然后根据服务器的响应对列进行重新排序。
我怎样才能做到这一点?
可以通过使用 DataTables 插件来做到这一点ColReorder
。启用插件后,可以fnColReorder(from, to)
像这样移动列:
var table = jQuery("#table_id").dataTable(settings);
table.fnColReorder(4, 10);//move the 4th column on the 10th position
table.fnAdjustColumnSizing();//a good idea to make sure there will be no displaying issues
但是在使用列索引时应该注意:这些是表列数组中的索引。这意味着,索引不必与表中的列号匹配(根据您的规范,可以隐藏某些列)。