Categories | Question details Back To List | ||
Connector and Combo Boxes Hello, It would be great if you could point me in the right direction on rendering/generating combo boxes (or select boxes) in cells when using the Connector. I suspect I would set my column type to co on the client side javascript and use the beforeRender event in the php to generate the options for the cell but apart from that I'm lost! Cheers, Answer posted by Support on Apr 15, 2009 08:08 It's a shame, but we have missed such feature in current version of connectors. While list of options can be defined in common way , through js code, there is no way to define the list of options through connectors. ( beforeRender allows to define details of each row, and through some custom coding it can be used to provide list of options, but it will be pretty ugly solution. You can a) use client side options initialization http://dhtmlx.com/docs/products/dhtmlxGrid/doc/articles/Selectbox_collections.html#grid_art_selectbox b) contact us directly at support@dhtmlx.com and we will provide latest dev. version of connectors with related documentation which can load options for selectboxes automatically ( based on defined value, distinct values from actual table, or separate table(s) ) c) use dhtmlXcombo in grid, which can be configured to use own connector http://dhtmlx.com/docs/products/dhtmlxGrid/doc/articles/Combo_excell.html#grid_art_comboexcell Answer posted by Nasir on Apr 15, 2009 08:32 No worries :) I hacked away at a bit and came up with a option of a bit of JS and some PHP. Just so some other poor bugger (like me) is reading this you need (along with the rest of the grid stuff) the following in your client file: dhtmlxcombo.js dhtmlxcombo.css /excells/dhtmlxgrid_excell_combo.js and the celltype is set to combo Step 1: Using Connector: I used the beforeRender event and hacked the grid_connector.php class to include another XML renderer without CDATA. I added these two functions to grid_connector.php so I could get around the <CDATA> problem so the XML would render correctly. function to_xml_start_no_cdata(){ if ($this->skip) return ""; $str="<row id='".$this->id."'"; foreach ($this->row_attrs as $k=>$v) $str.=" ".$k."='".$v."'"; $str.=">"; for ($i=0; $i < sizeof($this->name); $i++){ $str.="<cell"; $cattrs=$this->cell_attrs[$this->name[$i][1]]; if ($cattrs) foreach ($cattrs as $k => $v) $str.=" ".$k."='".$v."'"; $str.=">".$this->data[$this->name[$i][1]]."</cell>"; } return $str; } function to_xml_no_cdata(){ return $this->to_xml_start_no_cdata()."</row>"; } And changed this section of the render_set() function: while ($data = $this->db->get_data_named($res)){ if ($this->event->exist("beforeRender")){ //we have a custom data generation logic $data = new GridDataItem($data[$id[1]],$data,$field,$index++); $this->event->trigger("beforeRender",$data); $this->output.=$data->to_xml_no_cdata(); } So the renderer will output my <OPTION fields> in proper XML. I then set the cell attributes to match what the grid was expecting for the combo box cell: $data->set_cell_attribute("test","xmlcontent","1"); $data->set_cell_attribute("test","editable","0"); And then set the values for the cell in the box. $data->set_value("test",$field); So my cell at least was/is initialised with the dropdown value! Step 2: Using JS I wanted a chained select box so now that the first cell is populated (cell 11) I could populate cell 12 with a value and this saved me mucking around some more in the connector. I used the trusty onEditCell event and called this function: function doOnCellChanged(stage,rowId,cellInd,newValue,oldValue){ // cell 11 was the target cell if ((stage==2)&&(cellInd==11)){ mygrid.cellById(rowId,cellInd).getCellCombo(); var combo = mygrid.cellById(rowId,cellInd).getValue(); var gCombo1 = mygrid.getColumnCombo(12); gCombo1.loadXML("sub_cats.php?type=" + combo); } return true; } All in all it is clunky and am looking forward to your next version so I don't have to jump through these hoops!!! :) :) Cheers! |