Insert record into audit table on change
Insert record into audit table on change
kdavid@kremzeeks.com
Posts: 4Questions: 3Answers: 0
in Editor
I'm using Editor 1.5.0 with inline editing and everything works great. Is it possible to insert a record into an audit table anytime a change is made (Create/Update/Delete)? Thanks!
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
Look at the https://editor.datatables.net/reference/event/submitSuccess submitSuccess event. that's probably a good event to hook into for logging changes.
The best option is probably to have it done at the server-side with a server-side event. Have a read over this blog post which discusses server-side events and specifically considers the logging / audit use case.
Allan
Thanks for the quick reply ThomD. It started to lead me in the right direction. The link you posted Allan is exactly what I was looking for! Thanks again!
Hi Allan, I am trying to do the same and I have checked out your blog post on server side events.
Say I want to populate an audit log table each time an update is made.
using
->on('postEdit', function ($e,$id,$values,$row){});
So each time an edit is made, it triggers this method.
$id
returns the index$values
returns an array of all values in the row that are being edited. (what the row is being updated to)$row
returns the same as $values, as well as the datatable row numberHow do I retrieve what data has changed I.e. the before and after? Also what field is being updated?
Just to check-- when the serverside script does an update, does it update the entire row vs the particular field that is being edited?
Two options:
form-options
'ssubmit
option set to 'changed' which will cause only the changed values to be submitted (therefore, if you see a value, you know it has changed)preEdit
event which will read the database for the current values and then compare them to the submitted values, one by one.It depends. It will write to the database whatever values are submitted - which can be controlled by the client-side.
Regards,
Allan