How do you get soft-deleted items as an option in a select?
How do you get soft-deleted items as an option in a select?
We soft-delete most of our data, but I have not been able to find a solution to a problem. Given the following data, how do you have the Editor show the location in a select of the field you are editing even though it may not be in the option list.
{
"data": [
{
"DT_RowId": "row_1",
"employees": {
"name": "Jim Bob",
"location_id": "1",
...
},
"locations": { "name": "Soft-Deleted Location #1" },
},
...
],
"options": {
"employees.location_id": [
{ "value": "2", "label": "Active Location #2" },
{ "value": "3", "label": "Active Location #3" },
{ "value": "4", "label": "Active Location #4" }
],
...
}
}
The idea is that an item on the table we are looking at points to a lookup value that may have been soft-deleted, but we want to retain that value while we allow editing of another field. So, using the above data we want to update a "notes" field for "Jim Bob" without forcing it to update the "location_id" to one of the currently active locations. At the same time we want all new records to only have the active locations for options.
Answers
Use a database and soft delete the respective record. Afterwards ajax reload the data table.
In the options instance to select from you can exclude the soft deleted options while still showing them elsewhere in the data table depending on the WHERE clauses you use. Since the options instance has its own WHERE clause this usually isn't a problem.