HTML (DOM) sourced data
Basic example of a datatable with HTML (DOM) sourced data. The foundation for DataTables is progressive enhancement, so it is very adept at reading table information directly from the DOM. This example shows how easy it is to add searching, ordering and paging to your HTML table by simply running DataTables with basic configuration on it.
Javascript sourced data
At times you will wish to be able to create a table from dynamic information passed directly to DataTables, rather than having it read from the document. This is achieved using the data option in the initialisation object, passing in an array of data to be used. This examples shows the element being added by Javascript and then initialising the DataTable with a set of data from a Javascript array.
Ajax sourced data
DataTables has the ability to read data from virtually any JSON data source that can be obtained by Ajax. This can be done, in its most simple form, by setting the ajax option to the address of the JSON data source. The example below shows DataTables loading data for a table from arrays as the data source (object parameters can also be used through the columns.data option).
Nested object data
The information read from an Ajax data source can be arbitrarily complex, but still be displayed by DataTables through the columns.data option, which is particularly useful for working with JSON feeds in an already defined format. The columns.data option has the ability to read information not only from objects, but also from arrays using the same dotted object syntax as for objects.
Generated content for a column
In some tables you might wish to have some content generated automatically. This examples shows the use of columns.defaultContent to create a button element in the last column of the table. A simple jQuery click event listener is used to watch for clicks on the row, and when activated uses the row().data() method to get the data for the row and show a bit of information about it in an alert box.