How to Mark Records Deleted Without Physically Deleting Them
Description
In some applications, you may want to allow users to mark records as 'deleted' without physically deleting the record from the database. this can be done using a logical field to flag a record as deleted.
Discussion
Records can be "logically" deleted in a table by using a logical or bit field to track whether or not a record has been deleted. Using JavaScript, you can mark a record as 'deleted' by setting the value of the isDeleted field in the record to true. For example, the code below sets the deleted state for a row to true. The delete state is tracked by the field called "isDeleted":
{grid.object}.setValue('G','ISDELETED',rowNum,true);
You can take this a step further and include the ability to "undelete" a record. This is done by first checking if the record has been deleted and then setting the value of the isDeleted field to the appropriate value:
function toggleDelete(rowNum) { var isDel = {grid.object}.getValue('G','ISDELETED',rowNum); if (isDel) { {grid.object}.setValue('G','ISDELETED',false); } else { {grid.object}.setValue('G','ISDELETED',true); } }
The JavaScript method defined above can be called from the click event for a button in the same row as the record delete or undelete a record:
toggleDelete({grid.rowNumber});
For additional information and an explanation of how to add the "isDeleted" field to your database records, watch the video below: