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

Remove filter in Custom Filter

2 Answers 42 Views
Grid
This is a migrated thread and some comments may be shown as answers.
John Giblin
Top achievements
Rank 1
John Giblin asked on 18 Dec 2008, 09:36 PM
I was using the custom filter template example.  I wanted to add a no filter to the drop down, but I am not sure how to remove the filter from that column when it is selected

            private void list_ItemsRequested(object o, RadComboBoxItemsRequestedEventArgs e)
            {
                ((RadComboBox)o).DataTextField = this.DataField;
                ((RadComboBox)o).DataValueField = this.DataField;
                ((RadComboBox)o).DataSource = GetDataTable("SELECT DISTINCT " + this.UniqueName + " FROM Content_UserCalls WHERE " + this.UniqueName + " LIKE '" + e.Text + "%'");
                ((RadComboBox)o).DataBind();
                ((RadComboBox)o).Items.Insert(0, new RadComboBoxItem("(All)", ""));
            }



2 Answers, 1 is accepted

Sort by
0
Georgi Krustev
Telerik team
answered on 22 Dec 2008, 03:40 PM
Hi John,

I presume that the issue is caused because the filtering is made on the text field of the RadComboBox. To work properly when RadGrid is calling GetCurrentFilterValueFromControl method, the code has to return RadComboBox.SelectedValue, but not the RadComboBox.Text value.

Here is a code snippet:
 protected override string GetCurrentFilterValueFromControl(TableCell cell) 
 { 
     RadComboBox combo = (RadComboBox)cell.Controls[0]; 
     return combo.SelectedValue; //here I presume the returned value is from Text property
 }

When "(All)" option is selected, you have to check whether the selected value is String.Empty to preserve the text in RadComboBox. If it is, just set RadComboBox.Text with proper value (I suppose it will be "(All)"). If you omit to do that after this option is selected, the text will be deleted.

Here is a code excerpt implementing this suggestion:
  protected override void SetCurrentFilterValueToControl(TableCell cell) 
        { 
            base.SetCurrentFilterValueToControl(cell); 
            RadComboBox combo = (RadComboBox)cell.Controls[0]; 
            if ((this.CurrentFilterValue != string.Empty)) 
            { 
                combo.Text = this.CurrentFilterValue; 
            } 
            else  
            { 
                combo.Text = "(All)"
            } 
        } 

Best regards,
Georgi Krustev
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
John Giblin
Top achievements
Rank 1
answered on 22 Dec 2008, 03:49 PM
thanks! Yah,  I had the text value instead.  I should have seen that
Tags
Grid
Asked by
John Giblin
Top achievements
Rank 1
Answers by
Georgi Krustev
Telerik team
John Giblin
Top achievements
Rank 1
Share this question
or