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

[Solved] "Google Filtering" Demo, Declaratively

1 Answer 59 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Matthew
Top achievements
Rank 2
Matthew asked on 01 Apr 2009, 04:39 PM
Hey Folks,

After checking out the "Google Filtering" demo, and the accompanying article here http://www.telerik.com/support/kb/aspnet-ajax/grid/google-suggest-style-filtering-in-radgrid.aspx I set out to accomplish something similar. Everything worked well but I felt that there must be a better way than programatically swapping out the columns.

In my <Columns> Collection for the RadGrid I put the following:


    
    <Columns>
        <rg:TelerikGoogleFilterColumnNomenclature CurrentFilterFunction="Contains"  
            DataField="Nomenclature" FilterListOptions="VaryByDataType"
            ForceExtractValue="None"  HeaderText="Nomenclature" UniqueName="Nomenclature" >
        </rg:TelerikGoogleFilterColumnNomenclature>
        <rg:TelerikGoogleFilterColumnPartNumbers CurrentFilterFunction="Contains"
            DataField="PartNumber" FilterListOptions="VaryByDataType"
            ForceExtractValue="None" Groupable="False" HeaderText="PartNumber"
            ReadOnly="True" UniqueName="PartNumber">
        </rg:TelerikGoogleFilterColumnPartNumbers>
        <telerik:GridBoundColumn CurrentFilterFunction="NoFilter" DataField="Cost"
            DataType="System.Int32" FilterListOptions="VaryByDataType"
            ForceExtractValue="None" HeaderText="Cost" UniqueName="Cost" DataFormatString="{0:c}" >
        </telerik:GridBoundColumn>
...
...
...
</Columns>
And added an entry into web.config for the "rg" prefix like so:

 <add tagPrefix="rg" namespace="RadGrid" />


My Class file containing (straight from the article) the Filter Column Contained the following:

   public class TelerikGoogleFilterColumn : GridBoundColumn
    {

        //override the following to change path/method in a child

        public virtual string GetWebServicePath()
        {
            return  "./MyService.asmx";            
        }

        

        public virtual string GetWebServiceMethod()
        {
            return "SomeMethod";
        
        }



        protected override void SetupFilterControls(TableCell cell)
        {
            base.SetupFilterControls(cell);
            cell.Controls.RemoveAt(0);
            RadComboBox combo = new RadComboBox();
            combo.ID = ("RadComboBox1" + this.DataField);
            combo.ShowToggleImage = false;
            combo.Skin = "WebBlue";
            combo.EnableLoadOnDemand = true;
            combo.AutoPostBack = true;
            combo.MarkFirstMatch = false;
            combo.Height = Unit.Pixel(280);
            combo.Width = Unit.Pixel(300);
            //combo.ItemsRequested += new RadComboBoxItemsRequestedEventHandler(this.list_ItemsRequested);
            combo.SelectedIndexChanged += new Telerik.Web.UI.RadComboBoxSelectedIndexChangedEventHandler(this.list_SelectedIndexChanged);
            //setup web service info here
            combo.WebServiceSettings.Path = GetWebServicePath();
            combo.WebServiceSettings.Method = GetWebServiceMethod();
            combo.ShowToggleImage = false;
            combo.NoWrap = true;
            cell.Controls.AddAt(0, combo);
            cell.Controls.RemoveAt(1);
        }
... etc

This works out as I simply override the method/path values for different columns and dont have to manipulate the grid at runtime.


Just thought it would be useful for others. Works ALOT simpler for me anyways :)  

















1 Answer, 1 is accepted

Sort by
0
Yavor
Telerik team
answered on 06 Apr 2009, 08:44 AM
Hi Matthew,

Thank you for sharing your approach with the community. I am sure it will be useful.
In addition, you can also consider utilizing the new filter template, which offers much greater flexibility.

Sincerely yours,
Yavor
the Telerik team

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