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

Filtering Issue

20 Answers 726 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Michael
Top achievements
Rank 1
Michael asked on 25 Jun 2008, 08:59 PM
I am having difficulty with the filter of the RadGrid.  I know that I need to use the NeedDataSource event in order for filtering to work, so I did do that.  After doing that, the grid performs fine with sorting and paging, but the grid does not filter properly.  I am able to filter on the first column which is numeric, but the remaining column filters (all string values) will not work.  I tried to enter a value in and then select "Contains" as the filter and I get every row returned (none filtered).  In fact, if the view was already filtered due to the functioning filtering of the numeric column, then trying to filter on any other column will cause all records to show, meaning even the numeric filter column stops working.

My code is below.


 
                <telerik:RadGrid ID="rgProducts" runat="server" AllowFilteringByColumn="True"   
                    AllowPaging="True" AllowSorting="True" AutoGenerateDeleteColumn="True"   
                    AutoGenerateEditColumn="True" GridLines="None" Skin="Vista"   
                    ClientSettings-Selecting-AllowRowSelect="true"   
                    OnNeedDataSource="rgProducts_NeedDataSource" AutoPostBackOnFilter="true"><mastertableview><rowindicatorcolumn   
                        visible="False"><HeaderStyle Width="20px" /></rowindicatorcolumn><expandcollapsecolumn resizable="False" visible="False"><HeaderStyle Width="20px" /></expandcollapsecolumn><editformsettings><popupsettings scrollbars="None" /></editformsettings></mastertableview><clientsettings><selecting   
                        allowrowselect="True" /> 
                </clientsettings> 
                </telerik:RadGrid> 

        protected void rgProducts_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)  
        {  
            MyDataContext db = new MyDataContext();  
 
            rgProducts.DataSource =  
                from products in db.Product_GetByProductTypeId(1)  
                select products;   
        } 

In case it matters, this is code contained within a module for DotNetNuke.

Thanks!

Michael

20 Answers, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 26 Jun 2008, 06:24 AM
Hi Michael,

Have you set the AllowFiltering property of the GridBoundColumns to false? Try setting it to true and see whether Filtering is working properly.

ASPX:
<telerik:GridBoundColumn DataField="ProductName"  AllowFiltering="true"   HeaderText="ProductName" SortExpression="ProductName"  UniqueName="ProductName"
       </telerik:GridBoundColumn>                  
                    



Thanks
Shinu.
0
Michael
Top achievements
Rank 1
answered on 26 Jun 2008, 06:20 PM
They are already set that way:

            <Columns> 
                <telerik:GridEditCommandColumn> 
                </telerik:GridEditCommandColumn> 
                <telerik:GridBoundColumn UniqueName="ProductTypeName" HeaderText="Type" DataField="ProductTypeName" AllowFiltering="true"></telerik:GridBoundColumn> 
                <telerik:GridBoundColumn UniqueName="ProductId" HeaderText="ID" DataField="ProductId" AllowFiltering="true"></telerik:GridBoundColumn> 
                <telerik:GridBoundColumn UniqueName="ProComProductCode" HeaderText="Product Code" DataField="ProComProductCode" AllowFiltering="true"></telerik:GridBoundColumn>                              
                <telerik:GridBoundColumn UniqueName="ProductName" HeaderText="Name" DataField="ProductName" AllowFiltering="true"></telerik:GridBoundColumn> 
                <telerik:GridBoundColumn UniqueName="ShortDescription" HeaderText="Description" DataField="ShortDescription" AllowFiltering="true"></telerik:GridBoundColumn> 
            </Columns> 

Any other thoughts?

The ProductId when filtered by itself works just fine.... all the others break filtering when you try to use them.

Thanks!

Michael
0
Raymond Dalton
Top achievements
Rank 1
answered on 26 Jun 2008, 07:14 PM
I have noticed the same results from doing a grid rebind.

Within the onLoad event of my grid I add groupByExpressions and perform a rebind.  This fires the needDataSource event, similar to what you have below, except my datasource is declared in the grid tag as an objectDataSource, so I do not handle the event.

It appears that rebinding or resetting the data source clears the filter.

If I do not perform the rebind then the filtering works properly.  Is this a bug?   Is there a way to save the filter settings before the rebind or reset of the data source and then re-apply the filter settings afterwards?

Thanks,

Raymond
0
Princy
Top achievements
Rank 2
answered on 27 Jun 2008, 05:24 AM
Hi Raymond,

Go through the following help article which explains how to persist the runtime settings in RadGrid. 
Saving grid settings on a per user basis

Princy.
0
Raymond Dalton
Top achievements
Rank 1
answered on 27 Jun 2008, 01:45 PM
Just so I am clear.  You are saying that we need to save (persist) the filter settings before the grid is rebound, or in Michael's case before the datasource is re-set, and after the datasource is reloaded that the saved filter needs to be re-applied.

Is this correct?

0
Michael
Top achievements
Rank 1
answered on 27 Jun 2008, 03:35 PM
Hopefully it is clear that there are multiple issues being discussed here.  I want to make sure my initial issue is not lost in the shuffle (being selfish here...lol).  As far as I know, my issue has nothing to do with persisting user settings as there are no user settings to persist.  I simply dragged the RadGrid onto a user control, used dlinq to bind to provide a database context and a source of data (in this case a stored proc), implemented the NeedDataSource method.  Everything works great - except that only numeric columns can filter.  All string based filters fail.  This is pretty much out of the box setup as far as I can see.

Telerik, please chime in here.

Thanks - I greatly appreciate everyones thoughts and time!

Michael
0
Raymond Dalton
Top achievements
Rank 1
answered on 27 Jun 2008, 05:48 PM
Michael,

Sorry for the confusion.  I am actually interested in the answer to your issue.   The problem that I am having is the same as you are having.  My rebind fires the NeedDataSource event causing the data to be reloaded from the database, just like your resetting the datasource.

It appears that the filtering occurs on the existing grid data, and the data reload removes the applied filters.

I will just wait to see if they respond to your issue.

Thanks,

Raymond
0
Michael
Top achievements
Rank 1
answered on 30 Jun 2008, 05:37 PM
Telerik,

Can you please address this issue?

Thanks!

Michael
0
Sebastian
Telerik team
answered on 01 Jul 2008, 05:53 AM
Hello guys,

When you invoke the Rebind() method of the grid implicitly/explicitly the values inside the filter boxes will be cleared as this action will reset their state.

In order to keep the values inside them, consider storing them in a HashTable (for example) using the UniqueName of the column as a key and the actual filter pattern inside the filter box as a value.  Prior to the rebind operation, traverse the columns in the grid (based on the stored unique names in the HashTable) and recover the filter criteria in each header filter.
 
Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Michael
Top achievements
Rank 1
answered on 01 Jul 2008, 02:28 PM
Stephen,

Thanks for the response.  I am using the NeedsDataSource means of data binding.  I am never explicitly calling Rebind().  So, you are saying that in order for filtering to work I have to take the actions you mentioned?  Why, then, doesn't your RadGrid Online Demo mention this in the code samples for filtering?  Your demo makes it seem that the filter "just works".  There is nothing in the code about storing and resetting filter values, etc.

Please clarify, I am under the impression that the very simple case I am trying to do should work out of the box.

The other reason I think this is the case is due to the fact that the numeric column works just fine and I am not doing any of the things you mentioned.

Thanks!

Michael
0
Sebastian
Telerik team
answered on 02 Jul 2008, 12:25 PM
Hi Michael,

Indeed your observation is correct - please excuse me if my previous reply was misleading. What I meant actually is that if you set the filter values inside the filter boxes manually when other grid operation occurs, they will be lost when the Rebind() method is called explicitly/implicitly.

In order to provide more to-the-point answer for your case, I suggest you isolate a stripped working version of your project and send it enclosed to a formal support ticket. I will examine it in detail and will get back to you with my findings.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
Michael
Top achievements
Rank 1
answered on 06 Jul 2008, 02:31 AM
Telerik,

Well, I didn't solve this issue, but I think I worked around it.

In an attempt to get better performance, I ended up going with a LinqDataSource that used a View from the database... rather than the direct Linq query shown in my original post which was calling a stored procedure to get results in the NeedDataSource call.

Now the RadGrid is performing better, the paging is fast and the filtering works.  So, maybe this issue had to do with that I was calling a stored procedure with Linq before?  Can you confirm if this should impact filtering?  I can understand how the LinqDataSource using a view will result in better performance as most of the processing is done on the dataserver before bring the results over.  But with the stored procedure, all of the results would come back to the web server before getting filtered by the RadGrid, right?  That would explain performance, but not the issue I saw.

Anything you can confirm and add is appreciated as I want to make sure my assumptions are correct and also to see if there is an issue using stored procedure results and filtering. 

In case it matters, there are 13,420 records coming back prior to filtering.

Thanks!

Michael
0
Sebastian
Telerik team
answered on 07 Jul 2008, 08:47 AM
Hello Michael,

Indeed if you return all results from the stored procedure and then the filtering mechanism of the grid takes place, this may result in a slow-down when large amount of records are processed. You may consider performing the filtering operation directly at data source level (via your stored procedure) to speed up the performance or use LINQ in combination with a view as you already did.

Unfortunately I am still not able to determine the reason for the discrepancy you observed. Therefore, if the problem persists please prepare a stripped version of your project, illustrating it, and send it enclosed to a formal support ticket. I will examine your implementation in detail and will get back to you with more info on the subject.

Best regards,
Stephen
the Telerik team

Instantly find answers to your questions at the new Telerik Support Center
0
James McQuade
Top achievements
Rank 1
answered on 20 Feb 2009, 05:14 PM

 

Hi Stephen -

Based on what you mentioned -->

"When you invoke the Rebind() method of the grid implicitly/explicitly the values inside the filter boxes will be cleared as this action will reset their state.

In order to keep the values inside them, consider storing them in a HashTable (for example) using the UniqueName of the column as a key and the actual filter pattern inside the filter box as a value.  Prior to the rebind operation, traverse the columns in the grid (based on the stored unique names in the HashTable) and recover the filter criteria in each header filter."

Since my implementation uses custom paging, sorting and filtering and NeedDataSource is fired to implicitly rebind the grid, where should I be setting the header filters from the Hashtable --- please provide pointers on where and how to access the header filter to set the value entered by the user before the postback

0
Sebastian
Telerik team
answered on 24 Feb 2009, 10:13 AM
Hello James,

Here is how you can access and extract the values from the filter textboxes of the grid to operate with them at a later stage of the lifecycle:

http://www.telerik.com/help/aspnet-ajax/grdoperatewithfilterexpression.html
 
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 06 Mar 2009, 07:10 PM
"When you invoke the Rebind() method of the grid implicitly/explicitly the values inside the filter boxes will be cleared as this action will reset their state."

So in your examples of how to use the <FilterTemplate> and implement the filtering in code-behind your examples show that you are calling rebind() on the grid. Now why wouldn't you mention that doing so will actually clear out the filters selected by the user and reset all of the filter controls to their original value? Why don't you include the code to persist the values selected by the user in that example? As far as i'm concerned your examples are incomplete because they do not show this, so the developer (myself) gets the impression that everything just "works" when it doesn't. Who would possibly want the filter values all reset in a live application right after the user selects a filter value for a field? This should be in your examples. Incredibly frustrating.
0
jfkrueger
Top achievements
Rank 1
answered on 06 Mar 2009, 07:32 PM
Furthermore, if you use the <FilterTemplate> and are binding in the NeedsDataSource event, the filter expression is always blank in the NeedsDataSource event (because it is reset every time a filter is applied due to the call to rebind), so the link provided to attempt to persist the filter values selected by the user in the <filterTemplate> controls does not work.

Can someone at Telerik PLEASE provide me with a working, vb.net example of a grid that uses <FilterTemplates>, binds in the NeedsDataSource event, and allows for MULTIPLE column filtering rather than just one column? This would be a huge help. I've wasted too many days trying to get this to work.

Thank you.
0
Sebastian
Telerik team
answered on 07 Mar 2009, 08:28 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/defaultvb.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/defaultvb.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/defaultvb.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? This should ensure that the filter values will be retained across postbacks.

Best 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:37 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.
0
Sebastian
Telerik team
answered on 09 Mar 2009, 07:58 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.
Tags
Grid
Asked by
Michael
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Michael
Top achievements
Rank 1
Raymond Dalton
Top achievements
Rank 1
Princy
Top achievements
Rank 2
Sebastian
Telerik team
James McQuade
Top achievements
Rank 1
jfkrueger
Top achievements
Rank 1
Share this question
or