colReorder.transpose()
Convert one or more column indexes to and from current and original indexes.
Please note - this property requires the ColReorder extension for DataTables.
Description
ColReorder will change the indexes of columns when columns are reordered and it can often be useful to convert between the original column index and the current column index. This method provides that ability.
This ability to transpose between current and original values can be really useful if you have a reference to a column (column().index()
) and you want to ensure that your index refers to the correct column, regardless of ordering.
For example consider column index 0 is moved by the end user to index 5. You need to find out what its index is - this method provides that ability.
Note that if ColReorder is not enabled on the target table this method can still be safely called - the input data will simply be returned (since no transposition is required).
Type
function colReorder.transpose( idx [, direction ] )
- Description:
Get one or more current column indexes form their original index.
- Parameters:
Name Type Optional 1 idx
No The index, or array of indexes to transpose.
2 direction
Yes - default:toCurrent Set what transposition is required. This can be one of:
toCurrent
- the input value is an original index and you wish to know its current indextoOriginal
- the input value is the current index and you wish to know its original indexfromOriginal
- AstoCurrent
fromCurrent
- AstoOriginal
.
- Returns:
The transpose values
Example
Get the current column position of the column that was in index 0 when the table was created:
var table = new DataTable('#myTable', {
colReorder: true
});
$('#info').click(function (e) {
alert(table.colReorder.transpose(0));
});