{hero}

sort()

Since: DataTables 1.10

Sort the elements of the API instance's result set.

Description

The sort() method provides a way of sorted the data in an API instance's result set, which can be particularly useful if you then want to use that data for displaying to the end user - for example as a select list for a search input. This method should not be confused with order() which is used to order for records in the DataTable.

This method makes use of the fact that DataTables API objects are "array like", in that they inherit a lot of the abilities and methods of the Javascript Array type.

In this case, this method is a proxy for the Javascript Array.prototype.sort method and is provided as a utility method for the DataTables API. For more information about the original method, please refer to the Mozilla MDN documentation for sort.

Type

function sort( [ fn ] )

Description:

Sort the elements of the API instance's result set.

Parameters:
Returns:

The original API instance with the result set sorted as defined by the sorting conditions used.

Example

Sort the data from a column:

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

var data = table
	.column(0)
	.data()
	.sort();