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,

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
dhtmlx.com/docs/products/dhtmlxG … omboexcell

No worries :slight_smile: 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 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]]."";
        }
       
        return $str;
    }




function to_xml_no_cdata(){


        return $this->to_xml_start_no_cdata()."";

    }



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 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!!! :slight_smile: :slight_smile: Cheers!