-
Notifications
You must be signed in to change notification settings - Fork 78
API
Vanilla DataTables comes with a bunch of public methods for you to utilise. Just call the method after instantiating the plugin, like so:
var datatable = new DataTable("#myTable");
datatable.methodName();Please note that the API is not finalised and may change so check back once in while.
Refreshes the table. This will recount the rows, reset any search and remove any set message, but will not reset any sorting.
Load a chosen page.
Add new rows to the table. Must be an object with the rows propery set and the number of values for each row must match the column count of the table.
var dataTable = new DataTable("#myTable");
// New data to add
var newData = {
rows: [
[
"Cedric Kelly",
"Senior Javascript Developer",
"Edinburgh",
"6224",
"2012/03/29",
"$433,060"
],
[
"Airi Satou",
"Accountant",
"Tokyo",
"5407",
"2008/11/28",
"$162,700"
]
]
};
// add the rows
dataTable.addRows(newData);Sort the data by column and direction.
// sort the 4th column in descending order
dataTable.sortColumn(4, 'desc');Display a message in the table.
dataTable.setMessage("Hello, world!");Re-initialise the instance after calling the destroy() method.
Destroy the instance.
Export the table data to various formats.
The options argument must be an object of which the only required property is the type property which accepts either csv, txt, json or sql as it's value. The rest are optional:
{
download: true, // trigger download of file or return the string
skipColumn: [], // array of column indexes to skip
// csv
lineDelimiter: "\n", // line delimiter for csv type
columnDelimiter: ",", // column delimiter for csv type
// sql
tableName: "myTable", // SQL table name for sql type
// json
replacer: null, // JSON.stringify's replacer parameter for json type
space: 4 // JSON.stringify's space parameter for json type
};// Export the current page as a .csv file
dataTable.export({
type: "csv",
filename: "my-csv-file"
selection: dataTable.currentPage
});// Export pages 1-5 as an .sql file
dataTable.export({
type: "sql",
tableName: "sql_users",
selection: [1,2,3,4,5]
});// Export to .json file
dataTable.export({
type: "json",
});// Export to json string, omitting the 1st, 3rd and 5th columns
dataTable.export({
type: "json",
skipColumn: [0,2,4],
download: false // return formatted string instead of file
});Display printable version.
- datatable.init
- datatable.refresh
- datatable.update
- datatable.page
- datatable.sort
- datatable.perpage
- datatable.search
- perPage
- perPageSelect
- nextPrev
- prevText
- nextText
- firstLast
- firstText
- lastText
- searchable
- sortable
- truncatePager
- fixedColumns
- fixedHeight
- columns
- data
- ajax
- labels
- layout
- header
- footer
- table
- head DEPRECATED
- body DEPRECATED
- foot DEPRECATED
- wrapper
- container
- pagers
- headings
- options DEPRECATED
- initialized
- isIE DEPRECATED
- data
- activeRows DEPRECATED
- dataIndex
- pages
- hasRows
- hasHeadings
- currentPage
- totalPages
- onFirstPage
- onLastPage
- searching
- searchData