draw from JS array but paging on full data?
draw from JS array but paging on full data?
hi
1. i want to give data tables its current data to show from a Javascript array.
want the search to work on currently visible data
paging will be a mix of local data and data on server.
Initializing like this:
$('#jsonReport').DataTable( {
data: data,
columns: colsJson,
"paging": true,
"ordering": false,
"info": true,
"pageLength" : 6,
"pagingType" : "full_numbers",
"lengthMenu": [ [5, 10, 25, 50, -1], [5, 10, 25, 50, "All"] ]
} );
Initial screen looks okay. the objects are in the correct way.
q1 : is there a way to get a call back/ over ride the data on every page change? A way to provide a javascript function to call to get data for a page? it can accept current number of records per page and page number ?
My aim is to have client side processing of search (only on visible records) and hit server for other pages.
Answers
There is the
drawCallback
that is called every time the Datatable is drawn. There are a lot of API's documented here:https://datatables.net/reference/api/
One that might interest you is
page.info()
.You would need a function outside of Datatables to fetch the new data. Then you can use
clear()
thenrows.add()
anddraw()
to populate the new data and draw the table.Kevin
Thank you. Will try. Yes the API is extensive. Was hoping for a ready reference to copy and edit from :-)
Am able to change the data in the table. Is there any function i can call so that i can use the inbuild paging, but tell the component that there are actually X number of records on the server, so that it shows the correct next()/ previous buttons, and has a call back when next/ previous are called so I can get the data for that page and set it?
Not if you are using client-side processing. To get different data from the server for previous / next buttons, you'd need to use server-side processing.
Allan