validating create and edit is great using preSubmit, but delete has no DATA other than ID available, so what method do people use to validate prior to delete? I do not want to allow deleting an active customer, for example.
Good question! Would you could do is use the modifier() method to get the row being edited and then access its data using the DataTables API (row().data()).
For example:
if ( action === 'remove' ) {
var data = table.row( editor.modifier() ).data();
... validate with data
}
That works, thx. As an aside I have to say I think it would be simpler all around to pass the full DATA on all create,edit,delete events rather than trying to economize delete by allowing it to access ID only. It would seem to be more consistent, one less thing to treat special. Just a comment though. Thx for the tip
The thing is that preSubmit provides access to the data that is being sent to the server (so it can be checked or modified), but on delete no data is being sent since it isn't at all needed, hence why it isn't available.
However, this should be a bit easier I see! Perhaps the data should be passed in as an extra attribute, one representing the current data, not the new values. I'll look into that - thanks for the suggestion!
Answers
Good question! Would you could do is use the
modifier()
method to get the row being edited and then access its data using the DataTables API (row().data()
).For example:
Regards,
Allan
That works, thx. As an aside I have to say I think it would be simpler all around to pass the full DATA on all create,edit,delete events rather than trying to economize delete by allowing it to access ID only. It would seem to be more consistent, one less thing to treat special. Just a comment though. Thx for the tip
The thing is that
preSubmit
provides access to the data that is being sent to the server (so it can be checked or modified), but on delete no data is being sent since it isn't at all needed, hence why it isn't available.However, this should be a bit easier I see! Perhaps the data should be passed in as an extra attribute, one representing the current data, not the new values. I'll look into that - thanks for the suggestion!
Allan