Server-side DataTables and manipulating the source data and reloading the data in one call
Server-side DataTables and manipulating the source data and reloading the data in one call
So I've been combing through the API and examples and haven't found a way to do this, but here's a sample use case.
You have a DataTable, whose data is loaded via JSON by a server. Each row of the DataTable has a checkbox which you can click on or off.
Above the table, lies a button, "Delete selected rows" whose purpose is to issue an AJAX call to the server and delete the selected rows.
Sometimes, some of the selected rows will not be "delete-able" and therefore an error message will need to be shown, ideally below the offending row.
Now, it's easy to submit the necessary information to the server about which rows to delete, however, how does one refresh the table? And more importantly, how do you do this without doing two round trips to the server - ie. one to delete the selected rows, and one to refresh (fnDraw) the table (which won't easily handle showing error messages as each roundtrip to the server is a separate transaction).
Any thoughts?
James
You have a DataTable, whose data is loaded via JSON by a server. Each row of the DataTable has a checkbox which you can click on or off.
Above the table, lies a button, "Delete selected rows" whose purpose is to issue an AJAX call to the server and delete the selected rows.
Sometimes, some of the selected rows will not be "delete-able" and therefore an error message will need to be shown, ideally below the offending row.
Now, it's easy to submit the necessary information to the server about which rows to delete, however, how does one refresh the table? And more importantly, how do you do this without doing two round trips to the server - ie. one to delete the selected rows, and one to refresh (fnDraw) the table (which won't easily handle showing error messages as each roundtrip to the server is a separate transaction).
Any thoughts?
James
This discussion has been closed.
Replies
2) server replies with list of ID's not deleted, or ID's of deleted, or both
3) use the not-deleted list to signal which ones were not deleted
4) use fnDeleteRow to remove rows where ID's have been deleted.
So, in other words, calling fnDeleteRow will result in a second server call.
So - if you want to delete rows from the table but only make one XHR (entirely fair enough :-) ), what you would need to do is customise fnServerData or fnServerParams to send the extra information you need to make the server do whatever it needs to do (i.e. a delete flag and the row ideas to delete), modify the server script to do that and then complete the rest of the redraw request as normal.
Allan