Soft Delete (flag to delete but keep the record)
Problem
The tables I am working on are designed to store historical values. phpGrid handles CRUD services, however I don't want it to delete a record, rather I want it to update the end date with the current date and time instead.
Solution 1:
Use loadComplete event and unbind the click event for the delete button, then added your own event function and later with a Ajax call to your own custom 'soft delete' logic.
$onGridLoadComplete = <<<ONGRIDLOADCOMPLETE
function(status, rowid)
{
$("#del_order").unbind('click');
$("#del_order").click(function(){
if($(".ui-state-highlight").attr("id") != undefined){
if(confirm("Are you sure you want to delete this record?")){
var id = $(".ui-state-highlight").attr("id");
$.ajax({
url: "/phpgrid-ext/my-soft-delete.php?param1=value1&id="+id
}).done(function() {
$("#refresh_order").trigger("click");
});
}
}
else
{
alert("Please select a record to delete.");
}
return false;
});
}
ONGRIDLOADCOMPLETE;
$dg2->add_event("jqGridLoadComplete", $onGridLoadComplete);
Solution 2:
You can also set a different save script through the following function
set_jq_editurl("/admin/jqgrid/custom-edit.php");
then inside that file you can setup a switch for the request variable oper
(value is add, edit, or del) then use the "id" request field for your primary key. Finally all the other fields will be passed in by the name pulled from the database. This allows you to do custom save logic.
Solution 3:
Please see KB Soft delete using database trigger