Losing grid options when refreshing a grid using connectors

Hi
I have a grid that is populated using dhtmxconnectors thru a MYSQL database.
The grid has a couple of option cells created thru OptionsConnector.
These option cells load correctly and show the proper selections and can be editted properly on the initial load.
However, when I refresh the grid using grid.clearAll();grid.load(…), the grid refreshes but the options no longer show.

Any suggestions would be helpful.

Thank You
Rob.

Do you load options to the filter at the header of Grid?

To save filters at header you can use following code:

var filter_value=mygrid.getFilterElement(“column_index”).value

After grid was refreshed:

mygrid.load(url,function(){
mygrid.getFilterElement(“column_index”).value=filter_value;
mygrid.filterByAll();
});

Here is my PHP File
This handles the loading of the grid.
I hope this helps.

<?php require("base_connector.php"); require("grid_connector.php"); require("form_connector.php"); require("options_connector.php"); require_once("config.php"); $res = mysql_connect($mysql_server,$mysql_user,$mysql_pass) or die(mysql_error());; mysql_select_db($mysql_db,$res) or die(mysql_error());; $database = $mysql_db; $table = "company"; $sql = "SELECT * from ".$table; $result = mysql_query($sql,$res); $x = 0; $flds = ''; $cols = ''; $head = ''; $hidden = ''; $type = ''; $align = ''; $filter = ''; $width = '80,'; $srt = ''; while ($property = mysql_fetch_field($result)) { $cols = $cols.$property->name.','; $flds = $flds.ucwords($property->name).','; $hidden = $hidden.'false,'; if ($x == 0){$type = $type.'coro,';} else {$type = $type.'co,';} $align = $align.'left,'; $filter = $filter.'#connector_text_filter,'; $srt = $srt.'connector,'; if ($x == 2) { $width = $width.'*,';} else if ($x > 0) $width = $width.'100,'; $x++; } $cols = substr($cols,0,strlen($cols)-1); $flds = substr($flds,0,strlen($flds)-1); $hidden = substr($hidden,0,strlen($hidden)-1); $type = substr($type,0,strlen($type)-1); $align = substr($align,0,strlen($align)-1); $filter = substr($filter,0,strlen($filter)-1); $width = substr($width,0,strlen($width)-1); $srt = substr($srt,0,strlen($srt)-1); $head = $flds; $grid = new GridConnector($res); // $grid->enable_log("dhtmlxerrorLog",true); $grid->dynamic_loading(true); $grid->event->attach("beforeRender","formatImage"); $province = new OptionsConnector($res); $country = new OptionsConnector($res); $province->render_table("province","id","id(value), id(label)"); $country->render_table("country","id","id(value), id(label)"); $grid->set_options("province",$province); $grid->set_options("country",$country); // $grid->setHeader("Id,Name,Name,Salutation,Dept.,Address,City,Province,Country,Postal,Phone,Mobile,Email,Web,Company,Title,Notes,Profile"); $grid->setHeader($head); $grid->setInitWidths($width); $grid->setColSorting($srt); $grid->setColTypes($type); $grid->setColAlign($align); $grid->attachHeader($filter); $dhx_cols = ''; for ($l=0;$l<$x;$l++) {$dhx_cols = $dhx_cols.$l.',';} $_GET["dhx_colls"]= substr($dhx_cols,0,strlen($dhx_cols)-1); $grid->render_table($table,'code',$cols); mysql_close($res); function formatImage($row){ $data = $row->get_value('profile'); if (strpos($data,'image')){ $row->set_value("profile","");} } ?>

Then I use grid.load(“filename.php”);
to load the grid.

Thanks
Rob

Your code looks correct. Have you tried suggested workaround?

I will now. I wanted to make sure that I had the server side correct.
Thanks

Beware that when you are reloading not only data but structure of grid as well, connector may not provide list of options second time ( if you are using clearAll() you are safe, but if you are using clearAll(true), or sending grid’s structure during reloading - problem can occurs )

Hello,
What is the suggested way to refresh a grid if new data is added outside of the grid interface, that will allow options to be refreshed as well ?

I have tried clearAll(), without the ‘true’ and this only displays the first row of the grid after refresh. I assume that this should be something that is relatively easy to implement using connectors.

Thank you.

Refreshing options lists is not so common use-case.
Anyway, in current version you can try to use your original code and one next line before reloading data

mygrid._colls_loaded = false;

Hi
That seemed to work great!
Thank you so much. I will continue testing to see if there are any other issues, but this appears to fix the problem.
You guys rock!