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

Filtering with FilterTemplate does not work.

14 Answers 496 Views
Grid
This is a migrated thread and some comments may be shown as answers.
jfkrueger
Top achievements
Rank 1
jfkrueger asked on 06 Mar 2009, 06:03 PM

I have followed the example here to the letter:

http://www.telerik.com/help/aspnet-ajax/radgrid-filter-template.html

I have used the code-behind method since I am not using an EntityDataSource. However, it just doesn't work. After selecting a different item from the combobox it goes through the code to set the filter but then the combobox just gets reset to it's original value and nothing is filtered.

Here is my grid:

<telerik:RadGrid ID="RadGridEmployeeTransactions" runat="server"   
    AllowFilteringByColumn="True" AllowPaging="True" AllowSorting="True"   
    AutoGenerateColumns="False" GridLines="None" ShowGroupPanel="False" Width="620px" 
    EnableLinqExpressions="false">  
    <HeaderContextMenu> 
        <CollapseAnimation Duration="200" Type="OutQuint" /> 
    </HeaderContextMenu> 
    <PagerSTyle AlwaysVisible="true" Mode="NextPrevNumericAndAdvanced" /> 
    <MasterTableView> 
        <Columns> 
            <telerik:GridBoundColumn DataField="TransactionID" Groupable="False"   
                HeaderText="ID" ReadOnly="True" SortExpression="TransactionID"   
                UniqueName="TransactionID" 
                FilterControlWidth="50px">  
                <HeaderStyle HorizontalAlign="Center" Width="70px" /> 
                <ItemStyle HorizontalAlign="Center" Width="70px" />                                          
            </telerik:gridboundcolumn> 
            <telerik:GridBoundColumn DataField="DateSubmitted" Groupable="True"   
                HeaderText="Date Submitted" ReadOnly="True" SortExpression="DateSubmitted"   
                UniqueName="DateSubmitted" GroupByExpression="DateSubmitted" > 
                <HeaderStyle HorizontalAlign="Left" Width="130px" /> 
                <ItemStyle HorizontalAlign="Left" Width="130px" /> 
                <FilterTemplate> 
                    <telerik:RadComboBox ID="RadComboboxDateSubmittedFilter" 
                        runat="server" AutoPostBack="true" OnSelectedIndexChanged="RadComboboxDateSubmittedFilter_SelectedIndexChanged">  
                        <Items> 
                            <telerik:RadComboBoxItem Value="2009" Text="2009" /> 
                            <telerik:RadComboBoxItem Value="2008" Text="2008" /> 
                        </Items> 
                    </telerik:RadComboBox> 
                </FilterTemplate> 
            </telerik:gridboundcolumn> 
            <telerik:GridBoundColumn DataField="Tooltip" Groupable="True"   
                HeaderText="Transaction Type" ReadOnly="True" SortExpression="Tooltip"   
                UniqueName="Tooltip" GroupByExpression="Tooltip"   
                FilterControlWidth="200px">  
                <HeaderStyle HorizontalAlign="Left" Width="250px" /> 
                <ItemStyle HorizontalAlign="Left" Width="250px" /> 
            </telerik:gridboundcolumn> 
            <telerik:GridBoundColumn DataField="Status" Groupable="True"   
                HeaderText="Transaction Type" ReadOnly="True" SortExpression="Status"   
                UniqueName="Status" GroupByExpression="Status"   
                FilterControlWidth="100px">  
                <HeaderStyle HorizontalAlign="Left" Width="150px" /> 
                <ItemStyle HorizontalAlign="Left" Width="150px" /> 
            </telerik:gridboundcolumn> 
        </Columns> 
    </MasterTableView> 
    <ClientSettings AllowDragToGroup="True">  
    </ClientSettings> 
    <FilterMenu> 
        <CollapseAnimation Duration="200" Type="OutQuint" /> 
    </FilterMenu> 
</telerik:RadGrid> 

And here is the event handler:

    Public Sub RadComboboxDateSubmittedFilter_SelectedIndexChanged(ByVal sender As ObjectByVal e As RadComboBoxSelectedIndexChangedEventArgs)  
 
        Dim lBeginDate As String = "1/1/" & e.Value + " 12:00:00 AM" 
        Dim lEndDate As String = "12/31/" & e.Value  + " 11:59:59 PM" 
 
        Dim lFilterExpression As String = String.Format(CultureInfo.CurrentCulture, "([DateSubmitted] BETWEEN '{0}' AND '{1}'", lBeginDate, lEndDate)  
 
        RadGridEmployeeTransactions.MasterTableView.FilterExpression = lFilterExpression   
        RadGridEmployeeTransactions.MasterTableView.Rebind()  
 
    End Sub 

What gives? It seems like the filtering is a great feature but once you start getting into a complicated design (multiple master pages, user controls etc. all of the functionality is broken. I wouldn't even be trying to use the FilterTemplate if the normal filters worked on this page but they don't. No filteroptions are even displayed upon clicking the filter image.

Filtering on this grid is needed and I do not want to have to re-write my query so that I can pass in all of the filter criteria and then do all the filtering manually, that kind of defeats the purpose of using your controls.

Any help to get this resolved is greatly appreciated.

Thanks!

14 Answers, 1 is accepted

Sort by
0
jfkrueger
Top achievements
Rank 1
answered on 06 Mar 2009, 06:36 PM
I get the exact same results when placing the grid on a standalone web form that does not have any user controls or use any master pages. Upon changing the value in the dropdown list the page posts back and then all of the filter fields are reset (the combobox goes back to it's original value) and no filtering occurs.

Help!!!
0
jfkrueger
Top achievements
Rank 1
answered on 06 Mar 2009, 06:47 PM
I am binding on the NeedsDataSource event. Do I have to use a DataSource object (ObjectDataSource, SQLDataSource) for filtering to work?
0
jfkrueger
Top achievements
Rank 1
answered on 06 Mar 2009, 07:00 PM

And more info....

Ok, so with the <FilterTemplate> the fields that are strings KIND OF work. Meaning that they do filter the grid but all of the filter fields are still being reset to their original values so the filter that the user selected is gone once the grid is filtered and all of the comboboxes go back to the "Not Filtered" value.

So this means there are two problems here:

  • Filtering on Date fields or Numeric fields does not work at all.
  • Anytime any filter is selected or updated, all of the filter controls values are set back to the original values and what the user has selected is no longer selected.

I feel like i'm getting closer but could really use some help getting these issues ironed out.

Thanks!

0
jfkrueger
Top achievements
Rank 1
answered on 06 Mar 2009, 08:53 PM
Ok, got everything to work except the date field. Not sure what the deal is. I'm using the same date format as is stored in the database in my filter expression.
0
jfkrueger
Top achievements
Rank 1
answered on 06 Mar 2009, 09:04 PM
There is no dataformatstring applied on the grid. Here is an example of a date in the database: 1/1/2009 7:49:34 PM and in my filter expression looks like this: "[DateSubmitted] BETWEEN '1/1/2009 12:00:00 AM' AND '12/31/2009 11:59:59 PM'"

So why isn't the filter working?

Thanks!
0
Sebastian
Telerik team
answered on 07 Mar 2009, 08:20 AM
Hello Joe,

I am sorry to hear that you are having a hard time implementing filtering with different types of controls for your RadGrid for ASP.NET AJAX.

Generally speaking, the filter controls for the grid columns will vary based on their data type as shown in this online demo of the product:

http://demos.telerik.com/aspnet-ajax/grid/examples/generalfeatures/filtering/defaultcs.aspx

Additionally, you have the option to implement your own custom column with filter control of your choice as demonstrates here:

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

One more option you will have with the Q1 2009 release of the suite (expected in mid March) is declarative filter template option. It is also available in the Q3 2008 SP2 version (2008.3.1314) of the grid and presented in this example from the Q1 2009 Beta release of the product:

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

Finally, concerning the issue with the empty filters:
Can you please verify that you are using advanced binding for the grid intercepting its NeedDataSource event or using a data source control as in the demos linked above?

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
jfkrueger
Top achievements
Rank 1
answered on 07 Mar 2009, 10:38 PM
Hello, thanks for the response but I think maybe I didn't articulate my problem very well. In any case, I have figured out how to manually persist the filter values selected by the user after they update a filter and how to filter by more than one field so I have at least worked these issues out. Just wish I didn't have to manually do this stuff and that the control would handle it for me (I think it is supposed to but it just does not work for me when it is buried inside a WebUserControl and two layers of MasterPages.

I am a little confused though because you say that the filter values should be automatically persisted but in other posts the Telerik people say that a call to Rebind() will clear the filter values out and the user has to figure out a way to persist them. I have to call Rebind() because I am using <FilterTemplates> and am binding in the NeedsDataSource event. The reason I had to go this direction in the first place is because the normal filtering just didn't work in my situation. I would click on the little filter icon and no menu would pop up and nothing would happen. Oh well. I've pretty much got it figured out doing everything manually except for actually having the database re-queried upon the filtering of a specific date field (rather than just filtering the existing data) but that is in another post.

The filter on the date field is still not working though and I have no idea why. That is why I am attempting to just re-query the database instead of trying to use the filter, but I can't get that to work either so it is in another post.
0
Sebastian
Telerik team
answered on 09 Mar 2009, 07:56 AM
Hello Joe,

Indeed if you invoke explicitly the Rebind() method of the grid to refresh its state, the filter values in the textboxes might be lost and you may need to retain them explicitly. Since this is quite common scenario, I spoke with our developers on this subject and you may be happy to know that for the Q1 2009 release of RadControls for ASP.NET AJAX we will add a second grid to this online demo:

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

which will illustrate how to perform date range, date and slider range filter and persist the filter values when the grid is rebound. Please stand by for the next release of the suite, expected within a week and let us know whether the updated version of the demo is helpful to you.

Kind regards,
Sebastian
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Check out the tips for optimizing your support resource searches.
0
Lenny_shp
Top achievements
Rank 2
answered on 08 Apr 2009, 03:10 PM
(it was a beta link you might want to edit the link in the previous msg)
0
Sebastian
Telerik team
answered on 08 Apr 2009, 03:14 PM
Hi Lenny_shp,

Can you please specify the steps which lead to the error you depicted? I tried to replicate it on the online demo but unfortunately to no avail.

Kind regards,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
Lenny_shp
Top achievements
Rank 2
answered on 08 Apr 2009, 03:22 PM
(it was a beta link)
0
Sebastian
Telerik team
answered on 08 Apr 2009, 03:25 PM
Hello Lenny_shp,

There is new official version of the relevant demo which worked properly when I tested it under FireFox 3.0.8:

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

Greetings,
Sebastian
the Telerik team

Check out Telerik Trainer , the state of the art learning tool for Telerik products.
0
newbie
Top achievements
Rank 1
answered on 10 May 2010, 11:07 PM
Can somebody point me towards the solution for this issue.
I have multiple custom filters in my grid where I set the FilterExpression in the code.

My other filters work except for the date filters.
My filter expression looks like this: "([Date] BETWEEN '4/10/2010 12:00:00 AM' AND '5/10/2010 12:00:00 AM')"
where 'DATE' is a datetime field.

Please help.
0
newbie
Top achievements
Rank 1
answered on 18 May 2010, 11:43 PM
Any help on this.


Update: It seems like the datecolumn does not work with the between filter. The between filter works only with the gridboundcolumn.
I changed my date gilter to have Date < '' and date > '' and it seems to be working fine now.

thanks.

Tags
Grid
Asked by
jfkrueger
Top achievements
Rank 1
Answers by
jfkrueger
Top achievements
Rank 1
Sebastian
Telerik team
Lenny_shp
Top achievements
Rank 2
newbie
Top achievements
Rank 1
Share this question
or