This is a migrated thread and some comments may be shown as answers.

Set CustomFilterColumn CurrentFilterFunction

1 Answer 92 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 02 Jun 2009, 11:40 PM

Below is code that I have for my custom filter column.  Everything works great, however, if I select
"All" from the radcombobox I get "No records to display."  I am not sure if it is set up correctly to
either remove the the currentfilterfunction and value or how I set the column to no NoFilter when
"All" is chosen.  Any ideas?  Below is the code.  Thanks is advance.

Joshua

public class MyCustomFilteringColumn : GridBoundColumn  
{  
 
    //RadGrid will call this method when it initializes the controls inside the filtering item cells  
    protected override void SetupFilterControls(TableCell cell)  
    {  
        base.SetupFilterControls(cell);  
        cell.Controls.RemoveAt(0);  
        Telerik.Web.UI.RadComboBox combo = new Telerik.Web.UI.RadComboBox();  
        combo.ID = ("RadComboBox1" + this.UniqueName);  
        combo.ShowToggleImage = false;  
        combo.Skin = "Office2007";// "Web20";  
        combo.EnableLoadOnDemand = true;  
        combo.AutoPostBack = true;  
        combo.MarkFirstMatch = true;  
        combo.Height = Unit.Pixel(100);  
        combo.Width = Unit.Pixel(60);  
        combo.ItemsRequested += this.list_ItemsRequested;  
        combo.SelectedIndexChanged += this.list_SelectedIndexChanged;  
        cell.Controls.AddAt(0, combo);  
        cell.Controls.RemoveAt(1);  
    }  
 
    //RadGrid will cal this method when the value should be set to the filtering input control(s)  
    protected override void SetCurrentFilterValueToControl(TableCell cell)  
    {  
 
        base.SetCurrentFilterValueToControl(cell);  
        RadComboBox combo = (RadComboBox)cell.Controls[0];  
 
        if ((this.CurrentFilterValue != string.Empty))  
        {  
            combo.Text = this.CurrentFilterValue;  
        }  
    }  
 
    //RadGrid will call this method when the filtering value should be extracted from the filtering input control(s)  
    protected override string GetCurrentFilterValueFromControl(TableCell cell)  
    {  
        RadComboBox combo = (RadComboBox)cell.Controls[0];  
        return combo.Text;  
    }  
 
    private void list_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)  
    {  
        ((RadComboBox)o).DataTextField = this.DataField;  
        ((RadComboBox)o).DataValueField = this.DataField;  
        ((RadComboBox)o).DataSourceID = Global.GridDS;  
        ((RadComboBox)o).DataBind();  
        ((RadComboBox)o).Items.Insert(0, new RadComboBoxItem("All"""));  
    }  
 
    private void list_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)  
    {  
        GridFilteringItem filterItem = (GridFilteringItem)((RadComboBox)o).NamingContainer;  
 
        if ((this.UniqueName == "Index"))  
        {  
            //this is filtering for integer column type   
            filterItem.FireCommandEvent("Filter"new Pair("EqualTo"this.UniqueName));  
        }  
        //filtering for string column type  
        filterItem.FireCommandEvent("Filter"new Pair("Contains"this.UniqueName));  
    }  
}  

1 Answer, 1 is accepted

Sort by
0
Josh
Top achievements
Rank 1
answered on 04 Jun 2009, 10:45 PM
I was able to figure it out.  I changed
((RadComboBox)o).Items.Insert(0, new RadComboBoxItem("All"""));  
to
((RadComboBox)o).Items.Insert(0, new RadComboBoxItem("All""All"));  
and
        if ((this.UniqueName == "Index"))     
        {     
            //this is filtering for integer column type      
            filterItem.FireCommandEvent("Filter"new Pair("EqualTo"this.UniqueName));     
        }     
        //filtering for string column type     
        filterItem.FireCommandEvent("Filter"new Pair("Contains"this.UniqueName));    
 
to
//Since I only filter on strings          
if(((RadComboBox)o).SelectedValue != "All")  
            filterItem.FireCommandEvent("Filter"new Pair("Contains"this.UniqueName));  
//Since I do not have any values that will ever equal to "All"  
        if (((RadComboBox)o).SelectedValue  == "All")  
            filterItem.FireCommandEvent("Filter"new Pair("NotEqualTo"this.UniqueName)); 
Hope this helps.
Joshua
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Josh
Top achievements
Rank 1
Share this question
or