DataTables is a jQuery plugin to provide progressive enhancement to HTML tables. It provides the ability to search, order and page through data in a table. The plugin can be called on an existing HTML table so that clients can see a basic presentation without JavaScript and enhanced interaction if JavaScript is enabled. DataTables also has the ability to load data from ajax calls.
Our recommendation is to use DataTables when the table exceeds 20 rows or you have a number of columns that users might want to order by.
The Digital pattern library provides a JavaScript configuration and CSS styles to make the default DataTables look, feel and behavior more consistent the the rest of interface.
To use DataTables, first, you need to include the DataTables plugin. DataTables is loaded on the St Andrews CDN. These are the current file you need.
https://0.8.5/scripts/jquery.dataTables.min.jsAdditionally, you should load the Digital Pattern library's custom DataTables JavaScript and CSS. These files customise the look, feel and functionality of DataTables to match the pattern library.
https://0.8.5/scripts/datatables.jshttps://0.8.5/styles/datatables.cssAfter you have included the JavaScript and CSS dependencies, you can simply add a class of dataTable to any table and the DataTables will be called on it.
If you'd like to customise the look, feel or functionality, you can create DataTable instances with your own customisations, beginning with the pattern library defaults and modifying as needed. For example you might call DataTables like this:
$('tables.all_my_tables').DataTable({
// Custom options ...
});
For more information including a reference manual on DataTables see the DataTables website.
This table is made into a DataTable by the addition of the dataTable class.
| Email Address | First Name | Last Name | |
|---|---|---|---|
| greg@st.com | Greg | C | View forms |
| andy@hotmail.com | Andrew | Coomber | View forms |
| lee@hotmail.com | Lee | Angus | View forms |
| ankit@test.com | Ankit | Smith | View forms |
| test@test.com | Test | Testing | View forms |
| hannah@hannah.com | Hannah | Scott | View forms |
| greg@st.com | Greg | C | View forms |
| andy@hotmail.com | Andrew | Coomber | View forms |
| lee@hotmail.com | Lee | Smith | View forms |
| ankit@test.com | Ankit | Angus | View forms |
| test@test.com | Test | Testing | View forms |
| hannah@hannah.com | Hannah | Scott | View forms |
| greg@st.com | Greg | C | View forms |
| andy@hotmail.com | Andrew | Coomber | View forms |
| joeblogs@hotmail.com | Lee | Smith | View forms |
| ankit@test.com | Ankit | Jones | View forms |
| test@test.com | Test | Testing | View forms |
| hannah@hannah.com | Hannah | Smnith | View forms |
This table is made into a DataTable by a custom call in the JavaScript on this page.
| Email Address | First Name | Last Name | |
|---|---|---|---|
| greg@st.com | Greg | C | View forms |
| dairygoodness@hotmail.com | Andrew | Coomber | View forms |
| leecoomber@hotmail.com | Lee | Coomber | View forms |
| ankit@test.com | Ankit | Sawa | View forms |
| test@test.com | Test | Testing | View forms |
| hannah@hannah.com | Hannah | Thomson | View forms |
| greg@st.com | Greg | C | View forms |
| dairygoodness@hotmail.com | Andrew | Coomber | View forms |
| leecoomber@hotmail.com | Lee | Coomber | View forms |
| ankit@test.com | Ankit | Sawa | View forms |
| test@test.com | Test | Testing | View forms |
| hannah@hannah.com | Hannah | Thomson | View forms |
| greg@st.com | Greg | C | View forms |
| dairygoodness@hotmail.com | Andrew | Coomber | View forms |
| leecoomber@hotmail.com | Lee | Coomber | View forms |
| ankit@test.com | Ankit | Sawa | View forms |
| test@test.com | Test | Testing | View forms |
| hannah@hannah.com | Hannah | Thomson | View forms |