列在运行时重新排序

时间:2012-08-10 10:35:03

标签: javascript jquery datatables

我正在使用jQuery的DataTables插件,我想在加载数据后重新排序列。我知道我可以在创建桌子时重新排序它们。

我想要做的是绘制表格,从服务器加载数据,然后根据服务器的响应重新排序列。

我怎样才能做到这一点?

1 个答案:

答案 0 :(得分:1)

可以使用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

但是在使用列索引时应该引起注意:这些是表的列数组中的索引。这意味着,索引不必与表中的列号相匹配(根据您的规范,某些列可以隐藏)。

相关问题