My datatable doesn't refresh after AJAX Call
My datatable doesn't refresh after AJAX Call
Hello I have set up my data table. I am able to show data on page load. However when I click on next page, the call is made to server side and it returns data, however the data table doesn't refresh. Can anyone tell me what is going on ?
$(document).ready(function () {
//get Data Tables Query
buildDataTables();
});
function buildDataTables() {
if (!$.fn.DataTable.isDataTable('#locationTable')) {
$('#locationTable').DataTable({
"bServerSide": true,
"sAjaxSource": '/Home/GetDataTablesQuery',
paging: true,
"iDisplayLength": 10,
"aoColumns": [
{ "mData": "Address1", "name": "Address 1" },
{ "mData": "City", "name": "City" },
{ "mData": "Size", "name": "Approx SF" },
{ "mData": "StoreNumber", "name": "Store #" },
]
});
}
How do I refresh datatable data on pagination ??
This question has an accepted answers - jump to answer
Answers
The place to start is to see what data is returned for each page. This tech note will describe how to look at the ajax response for the page request. My guess is the same data is being returned for each page. Datatables will automatically update the display showing the data returned.
Kevin
Kevin,
I am able to show data on page load. On clicking on page 2 or another page the data doesn't refresh. I don't see any error on the console either.
are you using legacy datatables? The terms you are using are not consistent with the latest version of DataTables
you can do $('#dataTable).DataTable().draw(); after your ajax call.
That's why I suggested using using the steps in the tech note to look at the data returned from the server as a place to start. Is the data returned different when you go to page 2?
Kevin
At a guess the old
sEcho
value isn't changing. You need to have it reflect the value that was sent to the server.Allan
Allan - Bingo !!! That was the issue. I was always setting sEcho to 10
Everyone else thanks for your suggestions !!!
Make sure you cast it as an integer on the server-side to you don't have any possible security issues. If you just echo back what the client sends it can be open to attack.
Allan