Where with function disable auto refresh after update.

Where with function disable auto refresh after update.

BalaKrishnanDhanuskodiBalaKrishnanDhanuskodi Posts: 45Questions: 17Answers: 0

Happy Morning,

I have a data table to list all column related to data 'One' or 'Two' under the column 'target' - please refer the where syntax used in the PHP file. After using this where with a function the autorefresh option upon edit is not working - I have to refresh the whole page to see the updated content.

PHP File: code of where with function.

->where( function ( $r) {
 $r->where( 'target', 'One' );
$r->or_where( 'target', 'Two'  );
} )

Answers

  • allanallan Posts: 61,771Questions: 1Answers: 10,112 Site admin

    After using this where with a function the autorefresh option upon edit is not working

    That suggests that the newly added content doesn't match the query condition.

    If you could let me have a look at a test case showing the issue, that would be helpful.

    Allan

  • BalaKrishnanDhanuskodiBalaKrishnanDhanuskodi Posts: 45Questions: 17Answers: 0

    Thanks for the reply.

    Please find the test case.

    HTML

    <table cellpadding="0" cellspacing="0" border="0" class="display" id="keycard" width="100%">
    <thead>
    <tr>
    <th>name</th>
    <th>target</th>
    <th>display</th>
    </tr>
    </thead>
    </table>
    

    PHP

    Editor::inst( $db, 'keycard', 'id' )
    ->fields(
    Field::inst( 'name' ),
    Field::inst( 'target' ),
    Field::inst( 'display' )
    )
    
    ->where( function ( $r) {
    
    $r->where( 'target', 'One' );
    $r->or_where( 'target', 'Two'  );
    } )
    
    ->process( $_POST )
    ->json();
    

    JS

        (function($){
    
        $(document).ready(function() {
            var editor = new $.fn.dataTable.Editor( {
                ajax: 'php/table.keycard.php',
                table: '#keycard',
                fields: [
                    {
                        "label": "name:",
                        "name": "name"
                    },
                    {
                        "label": "target:",
                        "name": "target"
                    },
                    {
                        "label": "display:",
                        "name": "display"
                    }
                ]
            } );
    
            var table = $('#keycard').DataTable( {
                dom: 'Bfrtip',
                ajax: 'php/table.keycard.php',
                columns: [
                    {
                        "data": "name"
                    },
                    {
                        "data": "target"
                    },
                    {
                        "data": "display"
                    }
                ],
                select: true,
                lengthChange: false,
                buttons: [
                    { extend: 'create', editor: editor },
                    { extend: 'edit',   editor: editor },
                    { extend: 'remove', editor: editor }
                ]
            } );
        } );
    
        }(jQuery));
    
  • allanallan Posts: 61,771Questions: 1Answers: 10,112 Site admin

    If you submit the target field as either "One" or "Two" the table should be updated with the new data. Anything else would not be shown.

    Can you link to a page showing the issue please?

    Allan

  • BalaKrishnanDhanuskodiBalaKrishnanDhanuskodi Posts: 45Questions: 17Answers: 0
  • allanallan Posts: 61,771Questions: 1Answers: 10,112 Site admin

    Thanks. Something odd going on with the server-side - if I send:

    action: create
    data[0][name]: 2
    data[0][target]: Two
    data[0][display]: 4
    

    It is returning:

    {
        "data": [{
            "DT_RowId": "row_1",
            "name": "Bala",
            "target": "One",
            "display": "Segment 1"
        }]
    }
    

    Can you add ->debug( true ) immediately before the ->process( $_POST ) line please?

    Allan

  • BalaKrishnanDhanuskodiBalaKrishnanDhanuskodi Posts: 45Questions: 17Answers: 0

    Happy Morning Allan,

    Added,

    ->where( function ( $r) {
    
    $r->where( 'target', 'One' );
    $r->or_where( 'target', 'Two'  );
    } )
    ->debug( true )
    ->process( $_POST )
    ->json();
    
  • BalaKrishnanDhanuskodiBalaKrishnanDhanuskodi Posts: 45Questions: 17Answers: 0

    Happy Day Allan,

    As requested added ->debug( true ) to the code.

  • allanallan Posts: 61,771Questions: 1Answers: 10,112 Site admin

    I'm not seeing any debug information in the JSON returned from the server at http://lifeisbeautiful.ooo/DT/keycard.html (nice domain name btw :)). Was that chance deployed to the server?

    Allan

This discussion has been closed.