This site contains the legacy documentation for DataTables v1.9 and earlier for reference only.
DataTables 1.9 was End Of Life in 2014.
Do not use it for new work.
The current release of DataTables can always be found on
DataTables.net.
ColReorder v1.1.0
API
Like the initialisation options for ColReorder, the API is very simple:
fnOrder Show details
|
Get / set the order of the columns in the table.
As a getter: Get the current order of the columns, as an array. Note that the values given in the array are unique identifiers for each column. Currently these are the original ordering of the columns that was detected on start up, but this could potentially change in future.
As a setter: Set the order of the columns, from the positions identified in the ordering array given. Note that ColReorder takes a brute force approach to reordering, so it is possible multiple reordering events will occur before the final order is settled upon. |
Default: |
|
Input parameters: |
- array - optional - Array of column identifiers in the new order. Note that every column must be included, uniquely, in this array.
|
Return parameter: |
If an array is given to act as a setter, the API instance is returned for chaining. If used as a getter the array of column index information is returned. |
Code example: |
//
// Example 1: Swap the first and second columns
//
$(document).ready( function () {
var table = $('#example').dataTable();
var colReorder = new $.fn.dataTable.ColReorder( table );
colReorder.fnOrder( [1, 0, 2, 3, 4] );
})
//
// Example 2: Move the first column to the end for the table `#example`
//
$(document).ready( function () {
var table = $('#example').dataTable();
var colReorder = new $.fn.dataTable.ColReorder( table );
var curr = colReorder.fnOrder();
var first = curr.shift();
curr.push( first );
colReorder.fnOrder( curr );
} );
//
// Reverse the table's order
//
$(document).ready( function () {
var table = $('#example').dataTable();
var colReorder = new $.fn.dataTable.ColReorder( table );
colReorder.fnOrder(
colReorder.fnOrder().reverse()
);
} );
|
fnReset Show details
|
Reset the table columns to their original order (from the HTML). |
Default: |
|
Input parameters: |
|
Return parameter: |
ColReorder instance for chaining. |
Code example: |
$(document).ready( function () {
var table = $('#example').dataTable();
var colReorder = new $.fn.dataTable.ColReorder( table, {
"aiOrder": [ 4, 3, 2, 1, 0 ]
} );
$('#reset').click( function () {
colReorder.fnReset();
return false;
} );
} );
|