This repository has been archived by the owner on May 30, 2021. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 78
Adding a column from a remote source
Karl edited this page Sep 1, 2017
·
8 revisions
Adding a column from a remote source (AJAX) is simple with the columns()
API.
Let's say you've selected a column from your MySQL table and you want to include it in your datatable
instance. You can encode the column data as a JSON string
and fetch it:
{
heading: "Progress"
data: [
"37%",
"97%",
"63%",
"30%",
...
]
}
var addNewColumn = function() {
var columnData = "remote/data/url";
var xhr = new XMLHttpRequest();
xhr.addEventListener("load", function(e) {
if (xhr.readyState === 4) {
if (xhr.status === 200) {
// Parse the JSON string
var data = JSON.parse(xhr.responseText);
// Insert the new column
datatable.columns().add(data);
}
}
});
xhr.open('GET', columnData);
xhr.send();
};
- 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