Server-side processing giving a problem when trying to remove the only last row on the last page.
Server-side processing giving a problem when trying to remove the only last row on the last page.
I am using DataTables and Editor with server-side processing and wrote my own (simple) crud functions.
Loading rows, updating, removing and creating them, all is working.
I only have a problem when I try to remove the last row if this row is the only one row on the last page.
Let's say I have a record set of 11 rows, and I am showing 10 rows per page. Then on page 2, I have only 1 row, the 11th of the record set.
Below the process:
- The client sends a remove request to the server for row 11.
- The server is processing this request with success and deletes row 11.
- Server sends a JSON response back to the client with only an empty object (as described here https://editor.datatables.net/manual/server )
- But now the client sends a new request to the server with a wrong value for
start
. It is asking for rows starting from 10 and length 10.
I resolved this by checking the "start" value on server-side, but I would like to know how can I communicate to the client that the max number off rows available changed after the last successful delete?
This question has accepted answers - jump to:
Answers
you should be anyway. Part of the server side logic should set the number of total available rows on each return. The field name is recordsTotal.
If you are dealing with small data sets, it does not make sense to set serverSide to true. My code does not use serverside true unless I can expect to exceed 10,000 rows.
@bindrid.
First of all thanks for your responses!.
Yes, I know about the field recordsTotal, but in the documentation is stated that the server needs to respond with an empty object after a successful delete. (You can read this in the link I wrote in my initial part). Even how I tried to send a recordsTotal back after a successful delete, but it doesn't seem to make any difference.
Your second answer I agree and I will accept it as some kind of a solution.
OK thanks.
I think this is expected behavior. At least the behavior is the same with the Editor Server Side example:
https://editor.datatables.net/examples/simple/server-side-processing.html
You can go to the last page and delete all rows and see the client requesting the same last page. If @allan sees this post he can comment on whether this is expected behavior or a bug and if any alternatives.
Kevin
@kthorngren Kevin, also thanks for your comment.
Actually - I'm absolutely certain that this is a bug. It can be reproduced here. Go to the last page and delete all but one row. Then delete that last row and it will show "No match records found". The server-side processing script is doing the right thing - its responding to the request with an empty array (since there are no records after the requested index). Its a bug in the client-side library.
Let me look into that and I'll post back.
Allan
Fix committed here. Its specifically for when server-side processing is enabled - it isn't a problem when client-side processing (the overflow protection already works correctly for that).
It will be in 1.10.16 which I'm going to release soon (a few other little things to wrap up).
Regards,
Allan
@allan
OK, thanks!