Inline editor - Dropdown will not update database
Inline editor - Dropdown will not update database
I have a datatable that contains the contents of 3 joined tables, here is the server side:
Editor::inst( $db, 'enqitem', 'enqitemid')
->fields(
Field::inst( 'stock.salmasid' ),
Field::inst( 'stock.partnum' ),
Field::inst( 'stockitem.salsubid' ),
Field::inst( 'stockitem.condition1' ),
Field::inst( 'stockitem.supplier' ),
Field::inst( 'enqitem.enqitemid' ),
Field::inst( 'enqitem.cost' ),
Field::inst( 'enqitem.sale' ),
Field::inst( 'enqitem.qty' ),
Field::inst( 'enqitem.linedisc' ),
Field::inst( 'enqitem.leadtime' )
)
->leftJoin('stock', 'stock.salmasid', '=', 'enqitem.itemmasid')
->leftJoin('stockitem', 'stockitem.salsubid', '=', 'enqitem.itemid')
->where('enqitem.enqnr',141316)
->debug( true )
->process( $_POST )
->json();
And here is the editor:
let editor = new $.fn.dataTable.Editor( {
ajax: {
url: "ajax.php",
type: "POST"
},
table: "#dataTableSites",
fields: [{
label: "ID:",
name: "stock.salmasid",
type: "hidden"
},{
label: "ID:",
name: "stockitem.salsubid",
type: "hidden"
},{
label: "ID:",
name: "enqitem.enqitemid",
type: "hidden"
},{
label: "Part Number:",
name: "stock.partnum"
},{
label: "Condition:",
name: "stockitem.condition1",
type: "select",
options: [
{ label: "New", value: "New" },
{ label: "Used", value: "Used" },
{ label: "Repair", value: "Repair" }
]
},{
label: "Supplier:",
name: "stockitem.supplier",
type: "select"
},{
label: "Cost:",
name: "enqitem.cost"
},{
label: "Sale:",
name: "enqitem.sale"
},{
label: "Qty:",
name: "enqitem.qty"
},{
label: "Disc:",
name: "enqitem.linedisc"
},{
label: "Delivery Time:",
name: "enqitem.leadtime"
}
]
} );
It is set to edit inline like so:
$('#dataTableSites').on( 'click', 'tbody td:not(:first-child)', function (e) {
editor.inline( this, {
onBlur: 'submit'
} );
} );
If I change a the sale value (which is an inputbox) I can see in the debug the following:
{"query":"UPDATE `enqitem` SET `sale` = :sale WHERE `enqitem`.`enqitemid` =....
However when I change the condition (which is a dropdown) the database never updates. In fact the debug doesn't contain an UPDATE statement at all, only a SELECT.
Does the dropdown need to be set up differently?
This question has an accepted answers - jump to answer
Answers
Yes - if you are writing to a joined table rather than just the master table you need to have Editor submit the joined table's primary key as well (
enqitem.enqitemid
in this case I guess). When you are inline editing, by default it will only submit the edited field, but you can use theform-options
object to change that:Regards,
Allan
Thanks Allan!
Apologies but I've kind of re-posted this when I realised that it wasn't strictly a dropdown issue. The same fix works for that.