Is it possible to return more column data for a joined table that populates a select option control?
Currently I have leftJoin between two tables to populate a select control which has the CateringGroupID and CateringGroupDescription.
<?php
/*
* Editor server script for DB table Catering_Items
* 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\Upload,
DataTables\Editor\Validate;
// Build our Editor instance and process the data coming from _POST
Editor::inst( $db, 'Catering_Items', 'CateringID' )
->fields(
Field::inst( 'Catering_Items.CateringID' )->set(false),
Field::inst( 'Catering_Items.CateringDescription' )
->validator( 'Validate::notEmpty' )
->validator( 'Validate::maxLen',50),
Field::inst( 'Catering_Items.CateringGroupID' )
->options( 'CateringGroups','CateringGroupID', 'CateringGroupDescription')
->validator( 'Validate::dbValues' ),
Field::inst( 'CateringGroups.CateringGroupDescription' ),
Field::inst( 'Catering_Items.Available' )
->setFormatter(function ($val, $data, $opts) {
return ! $val ? 0 : 1;
})
)
->leftJoin( 'CateringGroups', 'CateringGroups.CateringGroupID', '=', 'Catering_Items.CateringGroupID' )
->process( $_POST )
->json();
?>
But what I would like to do is return an additional column from the leftJoined table called "CateringGroups.Inactive", so that I can disable the select option for a specific row depending on whether that CateringGroup record is Inactive or not.
If this can be done, how would you go about disabling that select option too.
I have been able to do it in another form not using dataTables; code snippet as below:
tdV.setAttribute("style","text-align: right;");
var col = $meta[j]['cname'];
var select = document.createElement('select');
var bSelected = false;
var bAvailable = true;
for (a = 0; a <$assoc.length; a++){
if ($tbl[i][col] == $assoc[a]['id']) {bSelected = true;} else {bSelected = false;}
if ($assoc[a]['Available'] == 1){bAvailable = true;} else {bAvailable = false;}
var option = new Option($assoc[a]['description'],$assoc[a]['id']);
if (bSelected) {option.setAttribute('selected','selected');}
if (!bAvailable) {option.setAttribute('disabled','disabled');}
select.setAttribute('class','form-control');
select.appendChild(option);
}
div.appendChild(select);