{hero}

columns().orderable()

Since: DataTables 2.0

Get information about the orderable status of the selected columns.

Description

This method provides the ability to programmatically check if the given columns are orderable by the end user (a click on the header cell) and optionally to get the ordering directions that the column can take, as defined by columns.orderSequence.

Type

function columns().order( [ directions ] )

Description:

Get information about the orderable status of the selected columns (enabled or not and what ordering directions are available).

Parameters:
Returns:

DataTables API instance containing true or false for each selected column, depending on the orderable state and if directions is undefined or false. If the parameter passed in is true the method will return information about what ordering directions the columns can take (see columns.orderSequence).

Example

Check if the first and second columns are orderable by the end user, and if so, order on them:

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

if (
	table
		.columns([0, 1])
		.orderable()
		.includes(true)
) {
	table
		.order([
			[0, 'asc'],
			[1, 'desc']
		])
		.draw();
}

Related

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