Unable to determine automatically field from source
Unable to determine automatically field from source
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
This discussion has been closed.
Answers
In your DataTable you have:
But there is no
categories.category
field in your Javascript Editor initialisation. I think you simply need to addeditField: '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
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.