Column reorders to runtinme

I am using the DataTables plugin for jQuery and I would like to reorder the columns after loading the data. I know that I can change the order in which they are created in the table.

What I would like to do is draw a table, load data from the server, and then, based on the serverโ€™s response, reorder the columns.

How can i achieve this?

+4
source share
1 answer

This can be done using the DataTables ColReorder . After the plugin is enabled, columns can be moved using fnColReorder(from, to) as follows:

 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 

But when using column indexes, special attention should be paid: these are indexes from an array of table columns. This means that the index does not have to match the column number in the table (some columns may be hidden according to your specification).

+1
source

All Articles