column.index()
Convert between column index formats.
Description
When working with the DOM you will typically be using the visible indexes of columns, since that is the information available in the DOM (when a column is hidden by DataTables, it is removed completely from the DOM, to be re-inserted in future if required to become visible again by column().visible()
). However, when working with the raw data of the table, you will typically want to work with the column data index. This method is provided to convert between the two formats.
Type
function column.index( type, index )
- Description:
Convert from the input column index type to that required.
- Parameters:
Name Type Optional 1 type
No The type of conversion that should take place:
fromVisible
ortoData
to convert from a visible index to the columns' data index.fromData
ortoVisible
to convert from a data index to the columns' visible index.
2 index
No The index to be converted
- Returns:
Calculated column index
Example
Show column index information about a clicked upon column:
var table = new DataTable('#myTable');
table.column(0).visible(false);
$('#example tbody').on('click', 'td', function () {
var visIdx = $(this).index();
var dataIdx = table.column.index('fromVisible', visIdx);
alert('Column data index: ' + dataIdx + ', and visible index: ' + visIdx);
});