DataTables example Default ordering (sorting)

With DataTables you can alter the ordering characteristics of the table at initialisation time. Using the orderDT initialisation parameter, you can set the table to display the data in exactly the order that you want.

The orderDT parameter is an array of arrays where the first value of the inner array is the column to order on, and the second is 'asc' (ascending ordering) or 'desc' (descending ordering) as required. orderDT is a 2D array to allow multi-column ordering to be defined.

The table below is ordered (descending) by the Age column.

NamePositionOfficeAgeStart dateSalary
NamePositionOfficeAgeStart dateSalary
Ashton Cox Junior Technical Author San Francisco 66 2009/01/12 $86,000
Michael Silva Marketing Designer London 66 2012/11/27 $198,500
Jackson Bradshaw Director New York 65 2008/09/26 $645,750
Paul Byrd Chief Financial Officer (CFO) New York 64 2010/06/09 $725,000
Olivia Liang Support Engineer Singapore 64 2011/02/03 $234,500
Serge Baldwin Data Coordinator Singapore 64 2012/04/09 $138,575
Garrett Winters Accountant Tokyo 63 2011/07/25 $170,750
Zenaida Frank Software Engineer New York 63 2010/01/04 $125,250
Vivian Harrell Financial Controller San Francisco 62 2009/02/14 $452,500
Tiger Nixon System Architect Edinburgh 61 2011/04/25 $320,800
Showing 1 to 10 of 57 entries

The Javascript shown below is used to initialise the table shown in this example:

1
2
3
4
5
$(document).ready(function() {
    $('#example').dataTable( {
        "order": [[ 3, "desc" ]]
    } );
} );

In addition to the above code, the following Javascript library files are loaded for use in this example: