Paginating by timestamp?

Paginating by timestamp?

CerinCerin Posts: 1Questions: 1Answers: 0

I have a strange case. I'm trying to use Datatables to display data retrieved via an API. However, this API is strange. It doesn't have the conventional pagination offset/limit features.

It only allows me to specify a timestamp of records to retrieve whose own created-datetime is after that timestamp, and then it only return 10 records.

However, since all records have a unique created-dateime, this can still implement pagination, albeit a little unconventionally. I just need to track the created-datetime of the last record in the last "page" of results returned, and then pass that into the API when I do a call to retrieve the next set of results.

How would I configure Datatables to support this? Is this something that's even supported by Datatables?

I've seen the alternative pagination documentation (https://datatables.net/examples/basic_init/alt_pagination.html), and while that does explain how to implement just the previous/next buttons (since I don't have any total page count), it doesn't explain how I might be able to configure it to use a record field (e.g. a datetime) as the "next" page number when issuing the next Ajax call.

Answers

  • allanallan Posts: 61,743Questions: 1Answers: 10,111 Site admin

    Is this something that's even supported by Datatables?

    Unfortunately no, sorry.

    However, I think you could get the same effect by using your own “paging” input which is effectively a calendar input - and when the value is changed, redraw the DataTable getting the data for that input. DataTables could then request the data for that date (using ajax.data to tell the server what data it needs) and draw that.

    Allan

This discussion has been closed.