columns().order()
Order the table by the selected columns.
Description
This method provides a useful alternative to the order()
method, allowing you to select the columns that you want to be ordered using the flexible columns()
selector and having them ordered in the direction specified.
Multi-column ordering is achieved by ensuring that the column selector matches multiple columns (single column ordering is performed if only one column is matched, or by using the column().order()
method). The order of the matched columns defines the priority sequence in which the ordering of the table is applied.
Please be aware that this method sets the ordering to apply to the table - it does not actually perform the order. In order to have the order 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();
.
Type
function columns().order( direction )
- Description:
Order the table, in the direction specified, by the columns selected by the
columns()
selector.- Parameters:
Name Type Optional 1 direction
No Direction of sort to apply to the selected columns -
desc
(descending) orasc
(ascending). Note this one direction is applied to all columns from the selector.- Returns:
DataTables API instance
Example
Sort by all columns with the class '.status':
var table = $('#example').DataTable();
table
.columns( '.status' )
.order( 'desc' )
.draw();
Related
The following options are directly related and may also be useful in your application development.