Datatable editor not updating , not seeing an update query in DevTools

Datatable editor not updating , not seeing an update query in DevTools

crcucbcrcucb Posts: 43Questions: 12Answers: 0

I have a data table (Addresses) who edit button opened AddressEditor and it contains two datatable fields called: residents and comments. Residents and Comments are both children of Addresses.

I am working on the edit for comments. When I click edit, the commentsEditor form opens and I can make chnages. When I click update, the update isn't posted back to the server.

I have debug enalebed in Addresses_Comments_Nested_DT.php, the php file and below are the contents from $_POST:
$_POST= {"data":{"row_26":{"Resident":"","ActLogDT":"2025-07-17 00:13:37.243","ActLogComments":"my updated commets","ReqFollowUp":"0","FollowedUp":"0"}},"action":"edit","AddressAID":"56"}

I don't see any errors in DevTools but I also don't see an update query in DevTools under Fetch/XHR Preview for Addresses_Comments_Nested_DT.php

This question has an accepted answers - jump to answer

Answers

  • crcucbcrcucb Posts: 43Questions: 12Answers: 0
    edited July 17

    This is the contents of my Addresses_Comments_Nested_DT.php

    <?php
    error_reporting(E_ALL);
    ini_set('display_errors', 'On');
    include 'php_functions.php';
    log_message("Start", '../logs/debug.log', 'DEBUG', $_SERVER['PHP_SELF'], False);
    log_message("\$_POST= " . json_encode( $_POST), '../logs/debug.log', 'DEBUG', $_SERVER['PHP_SELF'], True);
    /*
     * Editor server script for DB table Addresses
     * Created by http://editor.datatables.net/generator
     */
    
    // DataTables PHP library and database connection
    include( "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;
        if ( ! isset($_POST['AddressAID']) || ! is_numeric($_POST['AddressAID']) ) {
        echo json_encode( [ "data" => [] ] );
    }
    else {
    /*
     * Example PHP implementation used for the join.html example
     */
     log_message('AddressAID found in POST =' . $_POST['AddressAID'], '../logs/debug.log', 'DEBUG', $_SERVER['PHP_SELF'], false);
     Editor::inst( $db, 'ActLog' , 'ActLogAID')
        ->field( 
             Field::inst( 'ActLog.ActLogAID' ),
          Field::inst( 'ActLog.ActAID' ),
          Field::inst( 'ActLog.UserAID' ),
          Field::inst( 'ActLog.AddressAID' ),
          Field::inst( 'ActLog.ResidentAID' ),
          Field::inst( 'ActLog.ActLogDT' ),
          Field::inst( 'ActLog.ActLogComments' ),
          Field::inst( 'ActLog.ReqFollowUp' ),
          Field::inst( 'ActLog.FollowedUp' ),
          Field::inst( 'ActLog.ActLogInactive' ),
          Field::inst( 'ActLog.ActLogInactiveDateT' )
                ->setFormatter( Format::ifEmpty( null ) ),
          Field::inst( 'ActLog.ActLogInactiveUserAID' ),
          
            Field::inst( 'view_Residents.FullNameParty')->set(false),
              Field::inst( 'Act.ActName')->set(false),
              Field::inst( 'Act.ActSort')->set(false),
              Field::inst( 'Act.ColorAID')->set(false),
              Field::inst( 'Act.Rollup_Name')->set(false),
              Field::inst( 'Act.ActInactive')->set(false)
              
             ->options( Options::inst()
                   ->order( 'Act.ActLogDT' )  )
                  
    
        )   
         ->where( 'ActLog.AddressAID', $_POST['AddressAID'] )
         ->where( 'ActLog.ActLogInactive', 0 )
            ->leftJoin('view_Residents', 'view_Residents.ResidentAID', '=', 'ActLog.ResidentAID')
            ->leftJoin('Act', 'ActLog.ActAID', '=', 'Act.ActAID')
            
         ->on( 'preRemove', function () {
            // Disallow all delete actions since data cannot be removed completely
            return false;
         } )   
         ->debug(true) // Add this line
        ->process($_POST)
        ->json();
    
    }
    
  • crcucbcrcucb Posts: 43Questions: 12Answers: 0

    I removed other fields except the ids and comments. I haven't been able to isolate why the php editor isn't attempting to create an update query.

    Here is the reduced $_POST as reported by the PHP, attaching a screenshot of devtools. I spent about 8 hours on this today, I learned a bunch of stuff, just not what is happening.

    here is a link link, the steps are to click on edit address, go down to the comments, select either one and edit.
    https://jyorkejudge.org/Addresses.php

    $_POST= {"data":{"row_26":{"ActLogComments":"update me"}},"action":"edit","AddressAID":"56"}

  • allanallan Posts: 64,743Questions: 1Answers: 10,713 Site admin
    Answer ✓

    Thanks for the link. It appears that the edit for the comments is being submitted and this is was is being sent:

        "data[row_26][ActLogComments]": "act+log+hung1",
        "action": "edit",
        "AddressAID": "56"
    

    This is the response from the server:

    {
        "data": [
            {
                "DT_RowId": "row_26",
                "ActLog": {
                    "ActLogAID": "26",
                    "AddressAID": "56",
                    "ActLogComments": "act log hung"
                }
            }
        ],
        "options": [],
        "debug": [
            "Editor PHP libraries - version 2.4.3",
            {
                "query": "SELECT  [ActLogAID] as 'ActLogAID', [ActLog].[ActLogAID] as 'ActLog.ActLogAID', [ActLog].[AddressAID] as 'ActLog.AddressAID', [ActLog].[ActLogComments] as 'ActLog.ActLogComments' FROM  [ActLog] WHERE [ActLog].[AddressAID] = :where_0 AND  [ActLogAID] = :where_1 ",
                "bindings": [
                    {
                        "name": ":where_0",
                        "value": "56",
                        "type": null
                    },
                    {
                        "name": ":where_1",
                        "value": "26",
                        "type": null
                    }
                ]
            }
        ]
    }
    

    So it is being submitted, but not acted upon.

    The problem - at least part of it - is that you have:

    Field::inst( 'ActLog.ActLogComments' ),
    

    But in the JS for the field use name: 'ActLogComments', which tells Editor to submit the value with that name. I.e. it doesn't match the field name the server is expecting. Can you remove the name property for the field and just use the data one, which appears to be correct.

    Allan

  • crcucbcrcucb Posts: 43Questions: 12Answers: 0

    Thank you for getting me on the right path. I was so discouraged that I could not figure this out.

    I tried removing name: 'ActLogComments', from the editor definition and I received an error:

    Uncaught Error: Error adding field. The field requires a name option

    Because of your comments, I saw the name was just 'ActLogComments' was missing the table name. So I modified it to:
    name: 'ActLog.ActLogComments' and it's working.

    Since that is working, now I am going to try to figure out the soft delete.

  • allanallan Posts: 64,743Questions: 1Answers: 10,713 Site admin

    Doh, sorry. I should have said keep name but update it to the value of data and then remove data!

    Good to hear you have it working now.

    Allan

Sign In or Register to comment.