My code is below.
|<telerik:RadGrid ID="rgProducts" runat="server" AllowFilteringByColumn="True"|
|AllowPaging="True" AllowSorting="True" AutoGenerateDeleteColumn="True"|
|AutoGenerateEditColumn="True" GridLines="None" Skin="Vista"|
|visible="False"><HeaderStyle Width="20px" /></rowindicatorcolumn><expandcollapsecolumn resizable="False" visible="False"><HeaderStyle Width="20px" /></expandcollapsecolumn><editformsettings><popupsettings scrollbars="None" /></editformsettings></mastertableview><clientsettings><selecting|
|protected void rgProducts_NeedDataSource(object source, Telerik.Web.UI.GridNeedDataSourceEventArgs e)|
|MyDataContext db = new MyDataContext();|
|from products in db.Product_GetByProductTypeId(1)|
In case it matters, this is code contained within a module for DotNetNuke.
20 Answers, 1 is accepted
Have you set the AllowFiltering property of the GridBoundColumns to false? Try setting it to true and see whether Filtering is working properly.
|<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>|
Any other thoughts?
The ProductId when filtered by itself works just fine.... all the others break filtering when you try to use them.
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?
Is this correct?
Telerik, please chime in here.
Thanks - I greatly appreciate everyones thoughts and time!
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.
Can you please address this issue?
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.
the Telerik team
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.
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.
the Telerik team
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.
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.
the Telerik team
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
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:
the Telerik team
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.
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.
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:
Additionally, you have the option to implement your own custom column with filter control of your choice as demonstrates here:
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:
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.
the Telerik team
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.
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:
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.
the Telerik team