Can you initialize the datatable with JSON data when serverside = "true"?
Can you initialize the datatable with JSON data when serverside = "true"?
I noticed in one example (http://www.datatables.net/release-datatables/examples/server_side/defer_loading.html) that:
"When using DataTables with server-side processing the default behaviour is to have DataTables automatically go the server and load the data, removing anything which might already be on the page. However, this behaviour might not always be desirable when the first page of the table has already been preloaded in the HTML."
Is it possible to do this without preloading the data in HTML? More specifically, what I want to be able to do is to pass in JSON directly to the DataTable via fnAddData(). Unfortunately fnAddData() hits the server when server side processing is turned on.
The reason behind this is to not have to reproduce client-side code with HTML and JSON. It would be nice to use JSON for everything, even on initial Page Loads!
Hope that made sense... any thoughts?
James
"When using DataTables with server-side processing the default behaviour is to have DataTables automatically go the server and load the data, removing anything which might already be on the page. However, this behaviour might not always be desirable when the first page of the table has already been preloaded in the HTML."
Is it possible to do this without preloading the data in HTML? More specifically, what I want to be able to do is to pass in JSON directly to the DataTable via fnAddData(). Unfortunately fnAddData() hits the server when server side processing is turned on.
The reason behind this is to not have to reproduce client-side code with HTML and JSON. It would be nice to use JSON for everything, even on initial Page Loads!
Hope that made sense... any thoughts?
James
This discussion has been closed.
Replies
but I wonder if you could use ajax/json to retrieve data, put it into aaData, then initialize your datatable with that, with iDeferLoading and bServerSide
something like:
[code]
var mydata; // hold json response
$.ajax({
async: true,
url: url,
data: data,
success: function(jsondata) { mydata = jsondata; }
dataType: 'json'
});
$('#yourtable').dataTable({
bServerSide: true,
sAjaxSource: "your_db_url.php",
iDeferLoading: 10,
aaData: mydata
});
[/code]