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

Custom Filter saving the value

3 Answers 95 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 09 Jan 2009, 05:43 PM
I have been using 3 custom filters in a grid.  I wanted to save the value of the filter to filter on multiple values.  Do I have to change something in the code

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 cal 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.SelectedValue;
        }

            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("None", ""));
            }

        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));
        }

        public static DataTable GetDataTable(string query)
        {
            DataTable myDataTable = UserCallsDAO.GetFilterColumns(query);


            return myDataTable;
        }

    }

3 Answers, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 12 Jan 2009, 10:10 AM
Hi John,

One possible option in this case would be to save the filter expression in the PreRender event handler, where you can access the FilterExpression directly.
Additionally, the following article elaborates on a different approach on the filtering functionality, and its customization.
I hope this information helps.

Greetings,
Yavor
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 15 Jan 2009, 07:05 PM
I got it to work.  What I did was change this    

protected override string GetCurrentFilterValueFromControl(TableCell cell)
{
            RadComboBox combo = (RadComboBox)cell.Controls[0];
            return combo.SelectedValue;
}

to 
return combo.Text;

The only problem is that I wanted None to be in drop down list. anyway I can do this?
0
Yavor
Telerik team
answered on 16 Jan 2009, 09:03 AM
Hello John,

You can add the "None" text in the combo, as a statically declared item, and then append the other items from the datasource (after setting AppendDataBindItems="true").
In this way, you will have both the statically declared "None" text, and the other items coming from the database.

All the best,
Yavor
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
Grid
Asked by
John Giblin
Top achievements
Rank 1
Answers by
Yavor
Telerik team
John Giblin
Top achievements
Rank 1
Share this question
or