Joined editor table throwing unknown parameter hm_offices.OfficeName

Joined editor table throwing unknown parameter hm_offices.OfficeName

aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

So I have tried following the joined tables example to get this going and while the editor side of things works datatables is throwing this error when it redraws the table after an update.

Here is the debug info - http://debug.datatables.net/ufuces
And the code I'm working with - http://live.datatables.net/pediwure/1/edit?html,css,js,console,output

Can anyone tell me where I'm going wrong? I'm sure it is something simple but I can't see it for the life of me.

This question has an accepted answers - jump to answer

Answers

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin

    Just to confirm, the error is coming from: { "data": "hm_offices.OfficeName"},?

    The data shown in the debug trace doesn't appear to have any data at all for hm_offices - example object:

        {
            "DT_RowId": "row_1",
            "hm_rooms": {
                "id_office": "1",
                "Name": "Reception",
                "class": "No"
            }
        }
    

    Could you show me the PHP you are using with the join statement so I can see how it is configured please?

    Thanks,
    Allan

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0
    edited May 2015
    <?php
    
    /*
     * Editor server script for DB table hm_rooms
     * 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\Join,
        DataTables\Editor\Upload,
        DataTables\Editor\Validate;
    
    
    // Build our Editor instance and process the data coming from _POST
    Editor::inst( $db, 'hm_rooms', 'id_rooms' )
        ->fields(
            Field::inst( 'hm_rooms.id_office' )
                ->options('hm_offices', 'id_office', 'OfficeName')
                ->validator( 'Validate::notEmpty' ),
            Field::inst( 'hm_rooms.Name' )
                ->validator( 'Validate::notEmpty' ),
            Field::inst( 'hm_rooms.class' )
                ->validator( 'Validate::notEmpty' )
        )
        ->leftJoin('hm_offices', 'hm_rooms.id_office', '=', 'hm_offices.id_office')
        ->process( $_POST )
        ->json();
    
  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0
    edited May 2015
    {
        "data": [
            {
                "DT_RowId": "row_1",
                "hm_rooms": {
                    "id_office": "1",
                    "Name": "Reception",
                    "class": "No"
                }
            }
        ],
        "options": {
            "hm_rooms.id_office": [
                {
                    "value": "2",
                    "label": "Don Mueang"
                },
                {
                    "value": "1",
                    "label": "Siam Paragon"
                }
            ]
        }
    }
    

    Should be the data I'm getting back according to me

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    Hi Allan any ideas what I'm doing wrong?

  • allanallan Posts: 63,680Questions: 1Answers: 10,498 Site admin
    Answer ✓

    I've reformatted the JSON to make it a little clearer - as you will be abel to see, there is no hm_offices object in the data objects for each row.

    That is because there is no field that references hm_offices.OfficeName. You probably need to add something like:

    Field::inst( 'hm_offices.OfficeName' )
    

    Allan

  • aarontharkeraarontharker Posts: 41Questions: 11Answers: 0

    Thanks heaps Allan

This discussion has been closed.