Hi
I don’t want to delete any data but I want to be able to archive rows in a easy way (not editing a row).
The ideal behavior should be click in button (like delete, add…), ask for the reason and after ok set a value in field to know it’s archived and the reason.
Is there any way to do something like that?
Hi Abu You say third parameter to true to skip the default delete operation, but in the example I see this: \”If you pass last argument as true, functions will act as a filter and insert/update in ->table will be performed by grid after your function. If last argument is set to false, only your function handler will be executed and grid\’s internal implementation will be ignored.\” So I guess the third parameter should be false since I don\’t want to delete the register, just update a field, isn\’t it? In same documentation I can see that \”in the on_delete event only receive ID of grid\” so I guess this means that $data will have only the ID field of the row, right? (in my table the index field is ID) So the function should be like this: function delete_client($data) { global $grid; $grid->execute_query(\”UPDATE mytable set ARCHIVED=1 where ID={$data[\”params\”[\”ID\”]}\”); } Is that right?
unable to delete the post, sorry for the format, was typed in text mode 🙁
You need to use on_delete event handler (with thrid param to true to skip default delete operation) and write your custom code for soft delete by making a field like (is_deleted to 1).
And in grid select_command use this condition like SELECT … FROM table WHERE is_deleted=0.
Ref: https://www.gridphp.com/docs/grid-events/
PS: Custom events are supported in full version.
Hi Abu, thanks for the fast answer.
I’m a bit confused, you say that third parameter should be true but this will delete the register so I guess should be false, isn’t it?
Also I’ve read that in the delete events only the ID parameter will be passed, so the code should be something like this (in mytable the index field name is ID):
function add_client($data)
{
global $grid; $grid->execute_query(“UPDATE mytable SET archived=1 where ID={$data[“params”][“ID”]}'”);
}
Should it be right?
Yes, you are correct. Third param should be false in your case.
Code looks fine.
PS: Make sure you connect on_delete event with your function, not with on_insert.
Function name in your example (add_client) in creating confusion. Should be del_client or something.
Sorry for the topic, is not correct, I don’t need to move that data to another table, just mark it as archived and reason.