column().order()
Order the table by the selected column.
Description
This method provides a useful alternative to the order()
method, allowing you to select the column that you want to be ordered using the flexible column()
selector and having it ordered in the direction specified. As of v2 it also allows you to obtain ordering information about the selected column - determining if it is used in the current order of the table and what ordering direction.
Note that if the selector used for column()
matches more than one column, the result will be truncated to a single column. To perform multi-column ordering, please use columns().order()
or order()
.
Please be aware that when used as a setter, this method sets the ordering to apply to the table - it does not actually perform the order. To have the ordering performed, use the draw()
method, which can be called simply as a chained method of the order()
method's returned object - for example table.order([0, 'desc']).draw();
.
Types
function column().order()
- Description:
Determine if the table is being ordered by this column.
- Returns:
DataTables API instance containing
asc
,desc
or an empty string (indicating index data order) for the possible ordering applied to a column. If a column is not being ordered on,null
is given.
Example
Sort by the first visible column:
var table = new DataTable('#myTable');
table
.column('0:visible')
.order('asc')
.draw();
Related
The following options are directly related and may also be useful in your application development.