If statement to determine bulk vs single edit
If statement to determine bulk vs single edit
ggerbush
Posts: 7Questions: 3Answers: 0
I have one endpoint that handles editing a single row and another that handles bulk edits. I am trying to write a function to determine which url to pass to the editor for the edit/PUT method, but I cannot find a way to determine whether more than one row was edited. Is there a way to do this?
This question has accepted answers - jump to:
This discussion has been closed.
Answers
You might want to count the number of selected rows. If it is more than one you could conclude that it is bulk editing.
Here is an example how to count the number of selected rows:
https://datatables.net/reference/api/count()
You could use this in an event, e.g. on preEdit and put your if statement in there.
https://editor.datatables.net/reference/event/preEdit
Interesting one. Perhaps one option would be to have a unified end point at the server, which effectively acts as a proxy for the other two. It could do a count on the submitted data to check if it is a single or multiple row edit, and then send it on to the correct place.
I think on the client-side, you'd need to use
ajax
as a function to send it to different URLs, making your own Ajax call as needed.Regards,
Allan
Thank you, both, for the help!
@rf1234 I just realized that it is possible to select several rows, but whiles using keys to navigate, edit only one row. Is it possible to just get a count of the rows being edited?
@allan I am leaning towards this, but I would rather just have an if statement in the javascript directing bulk edits to one endpoint and a single edit to another.
"Is it possible to just get a count of the rows being edited?"
Not through a command I think. But of course you can analyze what is being sent to the server and count it yourself.
Here is an example where I analyze and manipulate what is being sent to the server myself:
As you can see it is easy to check whether the user action is "edit" and then play around with "d.data" and all the other nice objects in there ...
Thank you @rf1234 !