VOOZH about

URL: https://www.geeksforgeeks.org/jquery/datatables-order-option/

⇱ DataTables order Option - GeeksforGeeks


  • Courses
  • Tutorials
  • Interview Prep

DataTables order Option

Last Updated : 13 Jul, 2021

DataTables is a jQuery plugin that can be used for adding interactive and advanced controls to HTML tables for the webpage. This also allows the data in the table to be searched, sorted, and filtered according to the needs of the user. The DataTables also exposes a powerful API that can be further used to modify how the data is displayed.

The order option is used to specify the rows of the DataTable that have to be ordered and their direction. It accepts a two-dimensional array that allows the ordering to be specified in multiple columns at once. The column defined first would be given more priority in sorting. The default value is [[0, 'asc']], which means that only the first column is sorted in ascending order.

Syntax:

{ order: value }

Parameters: This option has a single value as mentioned above and described below.

  • value: This is a multi-dimension array value that specifies the rows and direction that the columns are to be sorted. The first value in each of the arrays is the column number to be ordered, which starts from '0' and the second one is its direction, which can be the values 'asc' or 'desc'.
 

Example 1: In this example, the 3rd column is sorted in ascending order.

Output:

👁 Image

Example 2: In this example, the 1st column is sorted in ascending order, and then the 2nd column is sorted in descending order.

Output: 

👁 Image
ascending order of 1st and descending order of 2nd column

Reference link:

Comment
Article Tags:

Explore