{hero}

columns().order()

Since: DataTables 1.10

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. As of v2 it also allows you to obtain ordering information about the selected columns - determining if they are used in the current order of the table and what ordering direction.

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 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 columns().order()

Description:

Determine if the table is being ordered by the selected columns.

Returns:

DataTables API instance containing asc, desc or an empty string (indicating index data order) for the possible ordering applied to each column selected. If a selected column is not being ordered on, null is given.

function columns().order( direction )

Description:

Order the table, in the direction specified, by the columns selected by the columns() selector.

Parameters:
Returns:

DataTables API instance

Example

Sort by all columns with the class '.status':

var table = new DataTable('#myTable');

table
	.columns('.status')
	.order('desc')
	.draw();

Related

The following options are directly related and may also be useful in your application development.