preEdit and postEdit - same $values értékek
preEdit and postEdit - same $values értékek
Hello,
I use PHP AJAX method for server side.
The preEdit and postEdit functions show the same values, both show the value AFTER editing.
This code change the status from 4 to 6. It works well, the database change the value correctly.
AJAX PHP:
function update_pr_pre ( $db, $action, $id, $values ) {
error_log(print_r($values,true)); //SHOWS 6, but it should be 4
}
function update_pr_post ( $db, $action, $id, $values, $row ) {
error_log(print_r($values,true)); //SHOWS 6, it's OK
}
...
$editor = Editor::inst( $db, 'table', 'id' )
->on( 'preEdit', function ( $editor, $id, $values )
{
update_pr_pre( $editor->db(), 'preEdit', $id, $values );
} )
->on( 'postEdit', function ( $editor, $id, $values, $row )
{
update_pr_post( $editor->db(), 'postEdit', $id, $values, $row );
} )
JS:
new $.fn.dataTable.Buttons( table1,
{
name: 'group11',
buttons:
[
{
extend: "selectedSingle",
editor: editor,
text: "Allow",
action: function ( e, dt, node, config )
{
tabledata = table.row( { selected: true } ).data();
if ( tabledata.table.status == 4 )
{
var todayDate = new Date().toISOString().slice(0,10);
editor
.edit( table.row( { selected: true } ).index(), false )
.set( 'table.date', todayDate )
.set( 'table.status', 6 )
.submit();
}
}
},
]
} );
Thank you and best regards:
Endre, Szak
This question has an accepted answers - jump to answer
This discussion has been closed.
Answers
And that is what they are supposed to show. Read the docs please:
https://editor.datatables.net/manual/php/events
If you want to detect whether a value has changed you can do that in many different ways. You can change the formOptions to submit: "changed"
https://editor.datatables.net/reference/option/formOptions.main
Then only the changed fields will be submitted to the server. Well you still don't know what the previous value was ... You can also do this client side by saving a field or more in a global variable on "initEdit" and then checking it on "initSubmit" like in this example from my own coding: I need to reset expiration notifications whenever the number of follow up days has changed and is being saved.