Loading DataTable with data from both server-side and client
Loading DataTable with data from both server-side and client
I've got a DataTable initialized something like this:
self.outputTable = DataTable({
bProcessing: true,
bServerSide: true,
ajax: {
url: "/filevalidation/getPage/",
type: 'POST',
data: function (d) {
d.timestamp = self.timestamp;
d.customerCode = self.selectedTenantInDB();
}
},
deferLoading: 0,
sPaginationType: "full_numbers",
columns: [
{ title: "Issue Type", data: "issueType" },
{ title: "File", data: "file" },
{ title: "Line", data: "lineNumber" },
{ title: "Rule", data: "rule" },
{ title: "Message", data: "text"}
]
});
And I've got it working well.
But I also want to be able to fill the datatable with data from an array generated on the client side when I click a button (and back to server-side when I click another button). I'm not sure how to approach this; do I have to destroy()
the table each time and reinitialize it? Is there a one line function that I can call to add the data array to the datatable? Do I have to set the client-generated data array similar to how I set the server-generated data array?
Answers
There is no option to switch between client-side and server-side processing in DataTables. The only option (if it is only the first draw that you want to be locally sourced) would be to use
ajax
as a function and detect that it is the first draw (draw
parameter in the submitted data) and return local data or make your own Ajax call.Allan