DataTables example - Multiple tables

Often you might wish to initialise multiple tables with a single statement. This is trivially done by using a jQuery selector which will pick up multiple tables.

The tables are independent for user control (i.e. user controlled paging on one table does not effect the others), but they do share the initialisation parameters given (for example if you specific the Spanish language file, all tables will be shown in Spanish). Additionally, the API can be used to manipulate both together, or independently.

The example below shows two tables initialised with a single line of code, through the use of the table.display selector (i.e. select all elements which have the class of table.display (which is suitable in this example, you might wish to use a different selector).

Name Position Office Age Salary
Name Position Office Age Salary
Tiger Nixon System Architect Edinburgh 61 $3,120
Garrett Winters Director Edinburgh 63 $5,300
Cedric Kelly Javascript Developer Edinburgh 22 $3,600
Jenna Elliott Financial Controller Edinburgh 33 $5,300
Rhona Davidson Integration Specialist Edinburgh 55 $6,730
Sonya Frost Software Engineer Edinburgh 23 $3,600
Quinn Flynn Financial Controller Edinburgh 22 $4,200
Dai Rios System Architect Edinburgh 35 $4,200
Doris Wilder Sales Assistant Edinburgh 23 $4,965
Gavin Joyce Developer Edinburgh 42 $4,525
Russell Chavez Director Edinburgh 20 $3,600
Michelle House Integration Specialist Edinburgh 37 $3,750
Martena Mccray Integration Specialist Edinburgh 46 $4,080
Miriam Weiss Support Engineer Edinburgh 64 $4,965
Odessa Jackson Support Engineer Edinburgh 37 $3,600
Elton Baldwin Data Coordinator Edinburgh 64 $6,730
Jennifer Acosta Javascript Developer Edinburgh 43 $2,875
Shad Decker Regional Director Edinburgh 51 $5,300
Michael Bruce Javascript Developer Edinburgh 29 $4,080
Name Position Office Age Salary
Name Position Office Age Salary
Jena Gaines System Architect London 30 $5,000
Haley Kennedy Senior Marketing Designer London 43 $4,800
Tatyana Fitzpatrick Regional Director London 19 $2,875
Michael Silva Senior Marketing Designer London 66 $3,750
Bradley Greer Software Engineer London 41 $3,120
Angelica Ramos System Architect London 36 $2,875
Jennifer Chang Regional Director London 28 $4,080
Suki Burks Developer London 53 $2,875
Prescott Bartlett Technical Author London 27 $6,730
Timothy Mooney Financial Controller London 37 $4,200
Bruno Nash Software Engineer London 38 $4,200
Hermione Butler Director London 47 $4,080
Lael Greer Systems Administrator London 21 $3,120

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

$(document).ready(function() {
	$('table.display').dataTable();
} );

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

The HTML shown below is the raw HTML table element, before it has been enhanced by DataTables:

This example uses a little bit of additional CSS beyond what is loaded from the library files (below), in order to correctly display the table. The additional CSS used is shown below:

div.dataTables_wrapper {
		margin-bottom: 3em;
	}

The following CSS library files are loaded for use in this example to provide the styling of the table:

This table loads data by Ajax. The latest data that has been loaded is shown below. This data will update automatically as any additional data is loaded.