Keep pagination on last page
Keep pagination on last page
Link to test case: https://dev.vmc.w3.uvm.edu/xana/climate_indicators/table
Debugger code (debug.datatables.net):
Error messages shown:
Description of problem:
I added some custom code to make it so the pagination disappears when there are less than 10 rows on my table (found here: https://stackoverflow.com/questions/11050826/disable-pagination-if-there-is-only-one-page-in-datatables )
The issue is that if you have multiple pages of rows in the table and then navigate to the last page, the pagination disappears so there's no way to go back to the previous page. Any ideas on how to remedy this?
Thanks!
This question has an accepted answers - jump to answer
Answers
This is the code I used, taken from that stackoverflow question:
Use the
rows()
API along with thecount()
API, something like this:The reason your code doesn't work is only the rows shown on the page are in the DOM.
Kevin
I'm not sure how to use that? I get the error Uncaught TypeError: $(...).rows is not a function
I'm putting it in the callback like this:
You need an instance of the Datatables API. Try:
$('#studyTable').DataTable().rows().count()
.Kevin
Hm, that doesn't hide the pagination at all anymore, even when there are less than 11 rows
The code seems to work here:
http://live.datatables.net/nupokuse/1/edit
The paging element is hidden. Comment out the first Datatable and uncomment the second and you will see that the paging element remains. If you still have issues please provide or update my test case to show the problem.
https://datatables.net/manual/tech-notes/10#How-to-provide-a-test-case
Note the use of
this.api()
indrawCallback
. You can access the API this way in most of the Datatables Callbacks.Kevin
If you use the #example2 table in your test case and search for "Ramos", only one entry shows up in the table but the pagination still shows. This is my issue- I'm filtering the table and want the pagination not to show when there are fewer than 10 entries.
You can use the
selector-modifier
of{search: 'applied'}
with therows()
API, like this:http://live.datatables.net/nupokuse/4/edit
Kevin
Yep, it just needs the search filter to be considered when counting the rows, see here: http://live.datatables.net/nupokuse/5/edit
Colin
that did it- thank you so much!