Problem Loading Selected Option with set_options


#1

This might be a duplicate topic but I’ve not been able to find a thread that addresses my specific issue so here goes!

I am creating a grid with data loaded from a database, and the grid contains combobox columns with options that are also loaded from the database.

I have 6 combo columns.
I tried using combo.load('data.php') for each combo but it was loading VERY slowly.

I found the ‘set_options’ method, documented here:
https://docs.dhtmlx.com/connector__php__grid_columns.html
And it loads the combo options very quickly! Except now the problem is that I cannot figure out how to display the selected values in the combos on the grid.

My application is meant to allow users to edit data in the grid and come back to it later. It uses a DataProcessor to save user-input to the database. But each time the page is reloaded, the data that was input in the combo columns is not visible.

The documentation provided for set_options does not really address this, and I have tried solving it on my own to no avail!
If anyone has any suggestions or solutions for me, it would be much appreciated!
Below is a sample of my code (simplified and with some specific details altered) so you can see exactly what I am doing.

Server Side:

$Host = "database";
$User = "username";
$Pass = "pw";
$DB = "dbname";
	
$dbh = new PDO('dblib:host='.$Host.';dbname='.$DB, $User, $Pass);
$dbh1 = new PDO('dblib:host='.$Host.';dbname='.$DB, $User, $Pass);

require("grid_connector.php");
require("options_connector.php");
require("db_pdo.php");

$grid = new GridConnector($dbh,"PDO");

// Set Combo Options
$option = new OptionsConnector($dbh1,"PDO");
$option->render_sql("select value_name as value, label_name as label from dbo.combo_table","value_name","value_name(value),label_name(label)");
$grid->set_options("option_id",$option);

// Render Grid
$grid->render_sql("select * from dbo.grid_table", "grid_id", "option_id, other, column, names, here");

(it’s like this but picture that “set combo options” block for all 6 combos)

Client Side:

myGrid = new dhtmlXGridObject("gridbox");
myGrid.setColTypes("combo, ed, ed, ed, ed");
		
// Show/Hide loading screen
myGrid.attachEvent("onXLS",function(){
    document.getElementById('wait').style.display='block';
});
myGrid.attachEvent("onXLE",function(){
    document.getElementById('wait').style.display='none';
});
myGrid.enableSmartRendering(true,50);
		
myGrid.enableEditEvents(true,false,false);
myGrid.load("connector.php");
myGrid.init();
        
var myDataProcessor = new dataProcessor("edit.php");
myDataProcessor.init(myGrid);
myDataProcessor.setTransactionMode("GET", false);

(I excluded probably irrelevant bits like .setHeaders and .setStyles, only included things that might be necessary to know)


#2

The cell value in your grid dataset will be the selected option of your combo