Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

datatables serverside processing with unknown number of rows

Does datatables have any support for server-side retrieving of data where the rocordsTotal count is not known in advance?

We have data for which the query to get the total-count is almost as expensive as just querying all records. It would be need if there was a way to let datatables know that the recordsTotal count is not known. Such functionality isn't documented. Is it supported?

Update 1: I think i didn't completely explained my problem and tried to ask an abstract version. I am using datatables.net/extensions/scroller plugin and it works with ajax option. If i use a large number for recordsTotal then the user can scroll to the button and i have no data to show there. The same thing is true with pagination, user can click on a page number that might not exist.

like image 880
Amin Roosta Avatar asked Nov 08 '15 18:11

Amin Roosta


1 Answers

I'm assuming by "TotalRecords" you mean "recordsTotal" field in the object the server returns to datatables. You could just take a count for the next N pages that meet your search criteria, assign this value to "recordsFiltered" and "recordsTotal", and not render the total records count via the "dom" option: http://datatables.net/reference/option/dom note the i component. It isn't built-in functionality, but it is a doable workaround for not knowing the table count in advance.

Doing this will let Datatables know that you have at least N more pages to look through via the "recordsFiltered" field so pagination works correctly. This way Datatables doesn't necessarily need to know exactly how many total records you have in order to work.

You could also use the footerCallback option to customize your data summary below the table. Take a look here: https://datatables.net/examples/advanced_init/footer_callback.html

Also, since you mentioned in a comment that you're using postgresql, I don't know if this is relevant to you or not (I've never used postgresql) https://wiki.postgresql.org/wiki/Count_estimate

like image 74
Jakotheshadows Avatar answered Oct 17 '22 07:10

Jakotheshadows