-
Notifications
You must be signed in to change notification settings - Fork 78
API
Please note that the API is not finalised and may change so check back once in while.
Returns a reference to the HTMLTableElement.
Returns a reference to the HTML <thead> element.
Returns a reference to the HTML <tbody> element.
Returns a reference to the HTML <tfoot> element.
Returns a reference to the main HTMLDivElement that wraps the entire layout.
Returns a reference to the main HTMLDivElement that contains the table.
Returns a reference to the currently displayed pagers.
Returns a live HTMLCollection of the the table headings.
Returns the current configuration options.
Returns true if the library is fully loaded and all HTML is rendered.
Returns true if the current browser is a version of MS Internet Exporer or MS Edge.
Returns a collection of all HTMLTableRowElements in the table.
Returns a collection of pages each of which contain collections of HTMLTableRowElements.
Returns true if the current table has rows.
Returns true if the current table has headings.
Returns the current page number.
Returns then number of pages.
Returns true if the current page is also the first page.
Returns true if the current page is also the last page.
Returns true if a search is currently being done and search results are displayed.
Returns a collection of HTMLTableRowElements containing matching results.
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.
NOTE: Prior to v1.3.0 this method was called
addRows
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.insert(newData);Sort the data by column and direction.
// sort the 4th column in descending order
dataTable.sortColumn(4, 'desc');Note that the column numbers are related to visible columns so if you have five columns and the first and second are hidden, then you only have three visible columns and hence the column numbers are 1,2,3 - not 3,4,5.
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
});Import data into the table from json or csv strings.
The options argument must be an object of which the only required properties are data and type. The data property should be the csv or json string and the type property should indicate the type of data being imported - csv or json.
{
type: "csv" // or "json"
data: // the csv or json string
// csv
lineDelimiter: "\n", // line delimiter for csv type
columnDelimiter: ",", // column delimiter for csv type
}; // Import a csv string
datatable.import({
type: "csv",
data: "Heading 1|Heading 2|Heading 3,Value 1|Value 2|Value 3,Value 4|Value 5|Value 6".
lineDelimiter: ",",
columnDelimiter: "|"
});Note that whilst checks are performed for valid
jsonstrings, none are present forcsvchecking so it's up to you to make sure the formatting is correct.
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