а

How to filter "combo" column


#1

I have grid where 7th column type is “combo”. This column has “#como_filter” shortcut in header.
Now combo filter is filled with ids. How to fill it with names?


#2

When grid fills #combo_filter or #select_filter it takes getValue() of the cell and add it as option. The same situation occurs when filter grid. Filter value is compared with cell value, not displayed text. In case of “combo”, “co” or “coro” eXCell types actual and displayed values are different.

To fill #combo_filter with names you can use “onCollectValues” event. Also you will need to customize filtration with “onFilterStart” event:

[code]grid.attachEvent(“onCollectValues”,collectComboValues);
grid.attachEvent(“onFilterStart”,filterGrid);

function collectComboValues(index){
if (index==7){

        var c={}; var f=[];
    	
        for (var i=0; i<this.getRowsNum(); i++){
            this.render_row(i);
            var text=this.cellByIndex(i,7).getTitle();
            c[text]=true;
        }
    
    	for (d in c) 
    		if (c[d]===true) f.push(d);
        
    	return f.sort();
    }
}

function filterGrid(indexes,values){
    var i=indexes.indexOf(7);
    if (values[i]){
        var combo=this.getColumnCombo(7);
        var combo_value=combo.getOptionByLabel(values[i]).value;
        this.filterBy(7,function(value){
            return (value.toString().toLowerCase()==combo_value.toString().toLowerCase()); 
        });
        return false;
    }
    return true;
}[/code]

Note this method may slow down grid performance because of to know displayed value of the cell appropriate row should be rendered. Also this code will not work in case of dynamic loading. If you need to manipulate with large number of rows it’s better to use server side filtration and use OptionsConnector to fill filter with options. More information can be found here docs.dhtmlx.com/doku.php?id=dhtm … iltering&s[]=optionsconnector