colReorder.order()
Get / set column order.
Please note - this property requires the ColReorder extension for DataTables.
Description
This method provides the ability to get the current column order of a DataTable and also to set a new order.
The reorder triggered by this method is immediate and there is no requirement to redraw the table.
Types
colReorder.order()
Get the current column order.
Returns:
array
Returns an array of column indexes. The column index given is the original column index, with its new position defined by the location in the returned array.
colReorder.order( order [, originalIndexes ] )
Set the column order.
Parameters:
Name | Type | Optional | |
---|---|---|---|
1 | order | No | |
Array of column indexes that define where the columns should be placed after the reorder. Please note that by default the column indexes given by this array are assumed to be the current column indexes, i.e. | |||
2 | originalIndexes | Yes - default:false | |
Since 1.3.0: The order array defines the positions that columns should be shown through column indexes but these indexes can be one of:
Set to be |
Returns:
DataTables.Api
DataTables API instance for chaining
Examples
Reverse the order of the columns in the table on a button click:
var table = new DataTable('#myTable', {
colReorder: true
});
$('#reverse').click(function (e) {
table.colReorder.order([5, 4, 3, 2, 1, 0]);
});
Restore the original order, regardless of any ordering applied (by passing the second parameter as true
):
var table = new DataTable('#myTable', {
colReorder: true
});
$('#reverse').click(function (e) {
table.colReorder.order([0, 1, 2, 3, 4, 5], true);
});