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

Extend Google Filter Example to allow multiple selections

1 Answer 61 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Andrew
Top achievements
Rank 1
Andrew asked on 09 Jul 2010, 02:59 PM
I have been using the Google based filtering example (http://demos.telerik.com/aspnet-ajax/controls/examples/integration/gridandcombo/defaultcs.aspx?product=grid) to extend the GridDropDownColumn to support a RadComboBox rather than text filter.  I am looking for a way to utilize the AutoCompleteSeperator to allow to multiple value selection.  So the user could pick 3 items from the list and get a result set of any rows with any one of those columns set.  Is this possible?  My working code is bellow, it follows the Google example closely.

using System;
using System.Collections.Generic;
using System.Web;
using Telerik.Web.UI;
using System.Web.UI.WebControls;
using System.Web.UI;
 
/// <summary>
/// Summary description for DDLColumn
/// </summary>
///
namespace DQCT.Controls
{
    public class DDLColumn : GridDropDownColumn
    {
        public DDLColumn()
        {
        }
 
        //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);
 
            RadComboBox ddl = new RadComboBox();
            ddl.ID = String.Format("_ddl{0}", this.UniqueName);
            //ddl.ShowToggleImage = false;
            ddl.EnableTextSelection = true;
            //ddl.Skin = "Office2007";
            ddl.AutoPostBack = true;
            //ddl.AutoCompleteSeparator = ";";
            ddl.MarkFirstMatch = true;
            ddl.Height = Unit.Pixel(100);
            ddl.DataTextField = this.ListTextField;
            ddl.DataValueField = this.ListValueField;
            ddl.DataSourceID = this.DataSourceID;
            ddl.SelectedIndexChanged += ddl_SelectedIndexChanged;
 
            cell.Controls.AddAt(0, ddl);
            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.SelectedValue = 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;
        }
 
        //handler for selected index changed
        private void ddl_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
        {
            GridFilteringItem filterItem = (GridFilteringItem)((RadComboBox)o).NamingContainer;
 
            filterItem.FireCommandEvent("Filter", new Pair("EqualTo", this.UniqueName));
        }
    }
}

1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 15 Jul 2010, 08:06 AM
Hello Andrew,

One possible option in this case would be to use the filter template:

http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx

You can accumulate the filter and trigger it at once, for example.
Give this approach a try and let me know how it goes and if any other questions arise.

All the best,
Yavor
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
Tags
Grid
Asked by
Andrew
Top achievements
Rank 1
Answers by
Yavor
Telerik team
Share this question
or