The OptionsConnector is used to retrieve 'value':'label' pairs based on the fields from the database. This connector can be useful, for example, to load sections to the Timeline, Units views of dhtmlxScheduler or the combo editor of dhtmlxGrid that require data to have 2 mandatory properties:
Note, OptionsConnector is used only in pair with schedulerConnector or gridConnector. To attach OptionsConnector, use the set_options() method that takes 2 parameters:
For example, to load sections to the Units view of dhtmlxScheduler, use the code as in:
<?php
include('connector-php/codebase/scheduler_connector.php'); // includes the file
// connects to the server with DB named 'sampleDB'
$res=new PDO("mysql:dbname=sampleDB;host=localhost","root","");
$list = new OptionsConnector($res, $dbtype);//initializes OptionsConnector
// retrieves data from the 'types' table
$list->render_table("types","type_id","type_id(value),name(label)");
$scheduler = new schedulerConnector($res, $dbtype); // initializes schedulerConnector
// attaches OptionsConnector to schedulerConnector
$scheduler->set_options("units", $list);
// retrieves data from the 'events' table
$scheduler->render_table("events","event_id","start_date,end_date,text,type");
?>
scheduler.createUnitsView({
name:"unit",
property:"type_id",
list:scheduler.serverList("units")
});
Pay attention to the fact that you mustn't change the second param "value" and the third param "value,label" in "render_complex_sql" query, otherwise the OptionsConnector won't work correctly.
// generate your sql
$sql = "SELECT ".
"option_id AS value, ". // field should be named "value" "option_label AS label ". // field should be named "label" "FROM ... ";
// init connector
$opts = new OptionsConnector($mysqli, "MySQLi");
// perform query
$opts->render_complex_sql(
$sql, // sql query from above
"value", // id field, important "value,label" // fields to select, both value,label are required);
Back to top