How can i excule a row from changing anothers rows value when updating it
How can i excule a row from changing anothers rows value when updating it
Currenty, each time a row is updated I store teh current timestpamp to keep a record. But, for a particulat column i dont want it to update the time. How can I achieve this
This is how initially it is
Field::inst('OL.followOn', 'followOn')
Field::inst('OL.updatedOn', 'updatedOn')
->set(true)
->setValue(date("Y-m-d H:i:s")),
This is another appraoch I tried but didn't seem to work
- Field::inst('OL.updatedOn', 'updatedOn')
->set(false),
// ->setValue(date("Y-m-d H:i:s")),
->on('postEdit', function ($editor, $values) {
$excludeColumn = 'followOn';
$shouldUpdate = true;
if (isset($values['data']) && is_array($values['data'])) {
foreach ($values['data'] as $key => $row) {
if (isset($row[$excludeColumn]) && count($row) === 1) {
$shouldUpdate = false;
}
}
} else {
$shouldUpdate = false;
}
if ($shouldUpdate) {
$editor->field('updatedOn')
->setValue(date("Y-m-d H:i:s"));
} else {
$editor->field('updatedOn')
->set(false);
}
})
This question has an accepted answers - jump to answer
Answers
Doing it in
postEdit
would be too late - it has already been written. Have you tried your code inpreEdit
?Allan
yes, I have tried it but wont work. How could I get the value of Follow On.
I would have expected that to work. Can you show the code you were using? Also, it looks like your parameters for the function at a little wrong (for
postEdit
or forpreEdit
).As the documentation notes, both get
$editor, $id, $values
parameters, and$values
is not the full HTTP object. It is the values for that row only. So you could use$values['followOn']
.Allan
In addition to Allan's remarks: Have you set the form options to "submit: 'changed'"?
https://editor.datatables.net/reference/type/form-options#submit
If not, all columns will be submitted to the server anyway. And you logic won't work.
The default for form editor is "submit: 'all'". So you would have to change this.
https://editor.datatables.net/reference/option/formOptions.main
Instead of that I used $_POST to get the values as $values was only giving me the row id. That helped me
Yup that will do it as well. Nice one. Problem solved then?