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 pletely explained my problem and tried to ask an abstract version. I am using datatables/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.
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 pletely explained my problem and tried to ask an abstract version. I am using datatables/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.
Share Improve this question edited Nov 11, 2015 at 17:46 Amin Roosta asked Nov 8, 2015 at 18:00 Amin RoostaAmin Roosta 1,0801 gold badge11 silver badges27 bronze badges 5- What kind of database do you work with? What kind of table / view is it, since it takes so long to get total count of rows? – davidkonrad Commented Nov 11, 2015 at 7:30
- @davidkonrad wiki.postgresql/wiki/Slow_Counting – Amin Roosta Commented Nov 11, 2015 at 8:27
- DataTable's basic server-side example - datatables/extensions/scroller/examples/initialisation/… - doesn't seem to be using the TotalRecords. Do you have a jsfiddle of your actual setup? – jjbskir Commented Nov 11, 2015 at 15:47
- jjbskir: The basic server-side example doesn't show any server-side code, which is why you don't see anything about it in that example. The "TotalRecords" he's referring to is likely the "recordsTotal" field in the object Datatables expects to be returned from the server. – Jakotheshadows Commented Nov 11, 2015 at 16:26
- Amin, I've updated my answer to elaborate a little more on the solution I'm proposing. I realized I left out a few critical details please reread. :-) – Jakotheshadows Commented Nov 11, 2015 at 17:09
1 Answer
Reset to default 5 +100I'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/reference/option/dom note the i ponent. 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/examples/advanced_init/footer_callback.html
Also, since you mentioned in a ment 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/wiki/Count_estimate