draw from JS array but paging on full data?

draw from JS array but paging on full data?

tgkprogtgkprog Posts: 3Questions: 1Answers: 0
edited July 2017 in Free community support

hi
1. i want to give data tables its current data to show from a Javascript array.

  1. want the search to work on currently visible data

  2. 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

  • kthorngrenkthorngren Posts: 20,302Questions: 26Answers: 4,769
    edited July 2017

    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() then rows.add() and draw() to populate the new data and draw the table.

    Kevin

  • tgkprogtgkprog Posts: 3Questions: 1Answers: 0

    Thank you. Will try. Yes the API is extensive. Was hoping for a ready reference to copy and edit from :-)

  • tgkprogtgkprog Posts: 3Questions: 1Answers: 0

    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?

  • allanallan Posts: 61,716Questions: 1Answers: 10,108 Site admin

    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

This discussion has been closed.