DataTables example HTML5 data-* attributes - table options

As of DataTables 1.10.5 it is now possible to define initialisation options using HTML5 data-* attributes. The attribute names are read by DataTables and used, potentially in combination with, the standard Javascript initialisation options (with the data-* attributes taking priority).

Please note that the attribute values must contain valid JSON data or a Javascript primitive, as required by jQuery's $().data() method. This means that double quotes should be used inside the attribute if needed for a string (see the data-order in this example).

Additionally, jQuery will convert a dashed string into the camel-case notation used by DataTables for its options. For example data-page-length is used to represent pageLength.

The table below shows the use of pageLength and order on the main table. Column options can also be defined on the table column cells, as shown by the use of the columns.orderable option on the fifth column below.

NamePositionOfficeAgeStart dateSalary
NamePositionOfficeAgeStart dateSalary
Garrett Winters Accountant Tokyo 63 2011/07/25 $170,750
Airi Satou Accountant Tokyo 33 2008/11/28 $162,700
Angelica Ramos Chief Executive Officer (CEO) London 47 2009/10/09 $1,200,000
Paul Byrd Chief Financial Officer (CFO) New York 64 2010/06/09 $725,000
Yuri Berry Chief Marketing Officer (CMO) New York 40 2009/06/25 $675,000
Fiona Green Chief Operating Officer (COO) San Francisco 48 2010/03/11 $850,000
Donna Snider Customer Support New York 27 2011/01/25 $112,000
Serge Baldwin Data Coordinator Singapore 64 2012/04/09 $138,575
Gavin Joyce Developer Edinburgh 42 2010/12/22 $92,575
Suki Burks Developer London 53 2009/10/22 $114,500
Thor Walton Developer New York 61 2013/08/11 $98,540
Jonas Alexander Developer San Francisco 30 2010/07/14 $86,500
Jenette Caldwell Development Lead New York 30 2011/09/03 $345,000
Jackson Bradshaw Director New York 65 2008/09/26 $645,750
Vivian Harrell Financial Controller San Francisco 62 2009/02/14 $452,500
Brielle Williamson Integration Specialist New York 61 2012/12/02 $372,000
Rhona Davidson Integration Specialist Tokyo 55 2010/10/14 $327,900
Michelle House Integration Specialist Sidney 37 2011/06/02 $95,400
Colleen Hurst Javascript Developer San Francisco 39 2009/09/15 $205,500
Michael Bruce Javascript Developer Singapore 29 2011/06/27 $183,000
Jennifer Acosta Junior Javascript Developer Edinburgh 43 2013/02/01 $75,650
Ashton Cox Junior Technical Author San Francisco 66 2009/01/12 $86,000
Michael Silva Marketing Designer London 66 2012/11/27 $198,500
Unity Butler Marketing Designer San Francisco 47 2009/12/09 $85,675
Jena Gaines Office Manager London 30 2008/12/19 $90,560
Showing 1 to 25 of 57 entries

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

1
2
3
$(document).ready(function () {
    $('#example').DataTable();
});

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