Unable to determine automatically field from source

Unable to determine automatically field from source

bkpagosbkpagos Posts: 3Questions: 2Answers: 0

Hi,
i keep getting this error when i leftjoin my tables in editor.

Here is my script :

editor = new $.fn.dataTable.Editor( {
        "ajax": "data/menu_editor.php",
        "table": "#display",
        "fields": [ 
                {
                "label": "Category :",
                "name": "products.category_id",
                "type" : "select",
                
            }, {
                "label": "Title:",
                "name": "products.title",
                
            },
            {
                "label": "Description :",
                "name": "products.description",
                
                
            },
            {
                "label": "Price :",
                "name": "products.price",
                
                
            },
            {
                "label": "Image:",
                "name": "products.image",
                
            }

        ]
    } );
 
    $('#display').DataTable( {
        dom: "Bfrtip",
        ajax: {
            url: "data/menu_editor.php",
            type: "POST"
        },
       
        columns: [
            { data: "products.title" },
             { data: "products.description" },
             { data: "categories.category"},
              { data: "products.price" },
               { data: "products.image" }

        ],
        select: true,
        responsive: true,
        buttons: [
            { extend: "create", editor: editor },
            { extend: "edit",   editor: editor },
            { extend: "remove", editor: editor }
            ]
    } ); 

Here is my .php :

<?php
 
/*
 * Example PHP implementation used for the index.html example
 */
 
// DataTables PHP library
include( "../DataTables/Editor-PHP-1.5.1/php/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, 'products')
    ->field(
        Field::inst( 'products.title' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'products.description' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'products.category_id')->validator( 'Validate::notEmpty' )->options('categories','id','category'),
        Field::inst( 'categories.category'),
        Field::inst( 'products.price' )->validator( 'Validate::notEmpty' ),
        Field::inst( 'products.image')
        
    )
    ->leftJoin( 'categories', 'categories.id', '=', 'products.category_id' )   
    ->process( $_POST )
    ->json();

This question has an accepted answers - jump to answer

Answers

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

    In your DataTable you have:

    { data: "categories.category"},

    But there is no categories.category field in your Javascript Editor initialisation. I think you simply need to add editField: 'products.category_id' to that line - this simply tells Editor what field to Edit when inline or bubble editing is activated on that cell.

    Allan

  • bkpagosbkpagos Posts: 3Questions: 2Answers: 0

    Just for the record, this error needed two actions : one action you mentioned, and one action that i had to redownload the scripts and css from your site, as something seemed to go wrong.

    Anyway, thank you very much for your help.

This discussion has been closed.