Delete row in database after form submit
Delete row in database after form submit

Hey there,
I have the following issue. I have a table with the select type "multi". Now I want to delete the selected rows after they got updated. Because they get copied in another table based on a mysql "before update" trigger and I do not need those rows in the current table anymore.
I thought about an editor event to solve this problem but I struggled with catching the rows I want to delete on "submitSuccess".
This is my current code for solving this issue:
editor
.title( "Transfer" )
.field( "name" )
.buttons( {
label: "transfer",
fn: function () {
var row = table.row( $(this).parents('tr') );
this.submit();
}
} )
.edit();
editor.on( 'submitSuccess', function () {
row.delete();
} );
Can any of you help me with this, or is there a better way to solve my problem?
Greetings
Daniel
This question has an accepted answers - jump to answer
Answers
You can get all the selected rows by calling
rows()
withselector-modifier
set to{selected: true}
. That could then be passed intoremove()
to remove them from the table both locally and on the server,Colin
Hey Colin,
thanks for your quick response!
Unfortunately, I can't get it integrated properly or I have misunderstood something.
My current code now looks like this:
Would you mind to tell me what I made wrong?
|Are they already deleted on the server-side? Or do you need to send a delete command to the server?
The way I'd approach this myself, is to use a
postEdit
event handler on the server to delete the row - Editor should then take care of removing the row from the client-side for you.Allan
Hey Allan,
thanks for your response!
Right, I need to send a delete command on update of the selected rows to the server. Now I took a look on your suggeseted approach and got the following code in my php file. However it does not work. Would you mind to tell me if I made something wrong here?
$row
there is a PHP array of data. It looks like you are treating it like a Javascript class instance.What you'd need to do is make use of the database connection in PHP. This part of the event handler page shows how it can be used, and this page has the full reference docs.
In this case, you might use something like:
Allan
Hi Allan,
thank you so much!
This solved my issue.
Kind regards,