(Using Editor) complex filter "or_where" function causing issues with updating the last row
(Using Editor) complex filter "or_where" function causing issues with updating the last row
Link to test case:
Debugger code (debug.datatables.net):
Version check
Check to see if your page is running the latest DataTables software.
LibraryInfoInstalledLatest
DataTablesNew version available1.10.181.10.21
AutoFillNew version available2.3.32.3.5
ButtonsNew version available1.5.61.6.3
ColReorder-1.5.2
EditorNew version available1.9.01.9.4
FixedColumns-3.3.1
FixedHeader-3.1.7
KeyTable-2.5.2
Responsive-2.2.5
RowGroup-1.1.2
RowReorder-1.2.7
Scroller-2.0.2
SelectNew version available1.3.01.3.1Check for common issues
Run automated tests to check for common and previously reported issues.
15 tests complete. No failures or warnings found!If you are having problems with your DataTables, please upload a data profile using the Upload option below, and post a support request in DataTables forums, with a link to a page showing the issue so we can help to debug and investigate the issue.
Error messages shown:
No error message shown
Description of problem:
I've been working on my "tableserver.php", to include some complex filter using "where" and "or_where", the filter portion works but now when we try to alter the last row of any column editable column it does not save properly or we have to refresh the page to show, the rows above the last row will save and automatically refresh. I'm using autofill and keytable. Below is an altered version of the code from the tableserver page any ideas why the or_where would cause issues with saving and auto refreshing properly? If I comment out the "or_where" function and add a ";" above it, everything works fine.
<?php
session_start();
// DataTables PHP library
include( "lib/Editor-PHP-1.9.0/lib/DataTables.php" );
// Alias Editor classes so they are easy to use
use
DataTables\Editor,
DataTables\Editor\Field,
DataTables\Editor\Format,
DataTables\Editor\Mjoin,
DataTables\Editor\Options,
DataTables\Editor\Upload,
DataTables\Editor\Validate,
DataTables\Editor\ValidateOptions;
$prevValues = [];
// runs only one per row
function getPrevValues( $db, $table, $id ){
global $prevValues;
$prevValues = $db->select( $table, '*', [ 'id' => $id ] )->fetch();
}
function logChange( $db, $table, $action, $id, $values ){
global $prevValues;
switch ($action) {
case "create":
$oldValues = [];
$newValues = $values;
break;
case "edit":
$oldValues = array_intersect_key(array_diff_assoc($prevValues,$values),array_diff_assoc($values,$prevValues));
$newValues = array_intersect_key(array_diff_assoc($values,$prevValues),array_diff_assoc($prevValues,$values));
break;
case "delete":
$oldValues = $prevValues;
$newValues = [];
break;
}
if (!empty($oldValues) || !empty($newValues)){
$db->insert( 'workqueueaudit', array(
'user' => isset($_SESSION['currentUser']) ? $_SESSION['currentUser'] : NULL,
'action' => $action,
'oldValue' => json_encode($oldValues),
'newValue' => json_encode($newValues),
'table' => $table,
'row' => $id,
'date' => date('c')
));
}
}
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'table', 'id' )
->fields(
Field::inst('column1'),
Field::inst('column2'),
Field::inst('column3'),
Field::inst('clientName'),
Field::inst('assignedTo'),
Field::inst('note'),
Field::inst('completed')
)
->where( function ($q){
global $roleName;
if(in_array("CRCUSER", $_SESSION['userRoles'])){
$q->where( 'completed', '1', '!=' );
$q->where( 'column3', 'NEGATIVE', '!=');
$q
->where( 'clientName', 'CLIENT 1', '!=')
->or_where( function ($r){
$r->where( 'clientName', 'CLIENT 1', '=');
$r->where( 'column3', 'POSITIVE', '!=');
$r->where( 'completed', '1', '!=' );
});
}else{
$q
->where( 'clientName', 'CLIENT 1', '!=')
->or_where( function ($r){
$r->where( 'clientName', 'CLIENT 1', '=');
$r->where( 'column3', 'POSITIVE', '!=');
$r->where( 'completed', '1', '!=' );
});
}
})
// Pre functions
->on( 'preEdit', function ( $editor, $id, $values){
getPrevValues($editor->db(), $editor->table()[0], $id);
})
->on( 'preRemove', function ( $editor, $id, $values){
getPrevValues($editor->db(), $editor->table()[0], $id);
})
//Post functions
->on( 'postCreate', function ( $editor, $id, $values, $row ){
logChange( $editor->db(), $editor->table()[0], 'create', $id, $values );
})
->on( 'postEdit', function ( $editor, $id, $values, $row ){
logChange( $editor->db(), $editor->table()[0], 'edit', $id, $values );
})
->on( 'postRemove', function( $editor, $id, $values ){
logChange( $editor->db(), $editor->table()[0], 'delete', $id, $values );
})
->process( $_POST )
->json();
?>
Answers
Found a work around to the issue by using only the "where" by doing this:
$q->where( 'clientName', "('CLIENT1', 'CLIENT2', 'CLIENT3', 'CLIENT4, 'CLIENT5', 'CLIENT6', 'CLIENT7', 'CLIENT8')", 'NOT IN', false);
$q->where( 'CONCAT(clientName,result)',"('CLIENT1POSITIVE')",'NOT IN', false);