Check documentation for the latest version of dhtmlxSuite OptionsConnector DHTMLX Docs


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:

  • value - the item id;
  • label - the item label.

Note, OptionsConnector is used only in pair with schedulerConnector or gridConnector. To attach OptionsConnector, use the set_options() method that takes 2 parameters:

  1. The name of a collection
  2. The OptionsConnector object

For example, to load sections to the Units view of dhtmlxScheduler, use the code as in:

 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
 $scheduler = new schedulerConnector($res, $dbtype); // initializes schedulerConnector
 // attaches OptionsConnector to schedulerConnector
 $scheduler->set_options("units", $list); 
 // retrieves data from the 'events' table


Important Notification

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
        $sql,           // sql query from above
        "value",        //  id field, important        "value,label"   //  fields to select, both value,label are required);
Back to top