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
function colReorder.order()
- Description:
Get the current column order.
- Returns:
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.
function colReorder.order( order [, originalIndexes ] )
- Description:
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.
0
will always refer to the first column in the table, regardless of the table ordering. The optional second parameter can be used to indicate that they should actually be treated as the original indexes.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:
- The current column index (i.e. even if column reordering has already happened)
- The original column index (i.e. the original index of the column before ColReorder has done any reordering)
Set to be
true
to indicate that the indexes passed in are the original indexes.false
orundefined
(default) will treat them as the current indexes.- Returns:
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);
});