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

[Solved] Set initial filter on a custom filter template

3 Answers 159 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Anthony
Top achievements
Rank 1
Anthony asked on 13 Oct 2009, 02:18 PM
I am using the Telerik Grid with a filter template, which I used the following example to create.
http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx


Everything is working great with the filter except for one condition. There are times in my application where I would like a filter to be applied when the page loads. I tried to accomplish this with the following code.

 

        protected override void SetCurrentFilterValueToControl(TableCell cell)  
        {  
            if (!(this.CurrentFilterValue == ""))  
            {  
                RadComboBox rcBox = ((RadComboBox)cell.Controls[0]);  
                rcBox.Items.FindItemByText(this.CurrentFilterValue).Selected = true;  
 
                if (HttpContext.Current.Session["SelectedClassName"] != null)  
                {  
                    HttpContext.Current.Session.Remove("SelectedClassName");  
                    ((GridFilteringItem)(((RadComboBox)rcBox).Parent.Parent)).FireCommandEvent("Filter"new Pair("EqualTo"this.CurrentFilterValue));  
                }  
            }  
        } 

The CurrentFilterValue is set and the filter event is fired, but when the page loads I get an error right after the grid tries to databind which says "There was a problem extracting DataKeyValues from the DataSource. Please ensure that DataKeyNames are specified correctly and all fields specified exist in the DataSource." Is there a way to implement this functionality with filtering?

3 Answers, 1 is accepted

Sort by
0
Pavlina
Telerik team
answered on 16 Oct 2009, 11:30 AM
Hello Anthony,

I recommend you review the following help article and let me know if it is useful for you.
Implementing filtering for template/custom columns


Best wishes,
Pavlina
the Telerik team


Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Anthony
Top achievements
Rank 1
answered on 16 Oct 2009, 01:13 PM
Hi Pavlina,

I took a look at the example you posted and it doesn't seem to have much in the way of setting the initial filter value. My problem is that sometimes when a user hits the page that my grid is on I need a column in the grid to already be filtered. I am calling the SetCurrentFilterValueToControl and GetCurrentFilterValueFromControl functions which is setting the correct filter values, however when I try to fire the filter event the column it isn't being filtered by those values, and I am getting the error that I posted in my previous post. I am using a dropdownlist to filter like in this example http://demos.telerik.com/aspnet-ajax/grid/examples/programming/filtertemplate/defaultcs.aspx
0
Pavlina
Telerik team
answered on 20 Oct 2009, 02:47 PM
Hi Anthony,

Please review the following link which elaborates on this subject and let me know if it is helpful for you:
PopulateDataKeys Method (Exceptions section)

Regards,
Pavlina
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
Grid
Asked by
Anthony
Top achievements
Rank 1
Answers by
Pavlina
Telerik team
Anthony
Top achievements
Rank 1
Share this question
or