2012-08-10 123 views
4

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

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

我该如何做到这一点?

回答

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 

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