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

Filtering and Rebind

7 Answers 369 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pratap
Top achievements
Rank 1
Pratap asked on 29 Sep 2008, 09:27 PM
I have a RadGrid binding via ObjectDataSource which always returns all the data. I enabled the column filtering and rely on RadGrid filtering functionality which works fine. However, when rebinding the grid the filter values are preserved in the filter texboxes but all the data are displayed as if no filter applied. Is that the behaviour by design?
I use the latest grid version.

7 Answers, 1 is accepted

Sort by
0
miksh
Top achievements
Rank 1
Iron
answered on 30 Sep 2008, 01:00 PM
Forgot to mention that the FilterExpression is used to set the default filtering.
0
Iana Tsolova
Telerik team
answered on 02 Oct 2008, 11:58 AM
Hi miksh,

Try clearing the grid filter expression as follows before you Rebind() it:

protected void BtnRebind(object sender, EventArgs e)  
{  
    RadGrid1.MasterTableView.FilterExpression = "";  
    GridColumn column = RadGrid1.MasterTableView.GetColumnSafe("<YourColumnName>");  
    column.CurrentFilterFunction = GridKnownFunction.NoFilter;  
    column.CurrentFilterValue = "";  
    RadGrid1.Rebind();  

Let me know if this works for you.

Sincerely yours,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
miksh
Top achievements
Rank 1
Iron
answered on 03 Oct 2008, 06:15 PM
Thanks but I need the opposite effect, i.e. re-apply the current filters after data rebinding. I thought that RadGrid does it automaticaly, doesn't it?
0
Iana Tsolova
Telerik team
answered on 06 Oct 2008, 12:30 PM
Hi miksh,

Indeed RadGrid should persist its filtering in the described situating. 

Please find the attached a sample project illustrating RadGrid filtering functionality. Try it on your end and let me know what differs in your case and if I missed something from your logic.

Best wishes,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
miksh
Top achievements
Rank 1
Iron
answered on 06 Oct 2008, 02:32 PM
Didn't find how to attach the file so the changes are:
1. Use .net 3.5 telerik dlls (ver. 2008.2.826.35)
2. Change Default1.aspx to (added FilterExpression - btw I couldn't add the filter for any field type of string, e.g. (Title LIKE '%Manager%'))
<%@ Page Language="C#" AutoEventWireup="true" CodeFile="Default1.aspx.cs" Inherits="_Default" %> 
<%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %> 
 
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> 
 
<html xmlns="http://www.w3.org/1999/xhtml">  
<head runat="server">  
    <title>Untitled Page</title> 
</head> 
<body> 
    <form id="form1" runat="server">  
        <asp:ScriptManager ID="ScriptManager1" runat="server">  
        </asp:ScriptManager> 
        <div> 
            <asp:Button ID="Button1" runat="server" Text="Rebind" OnClick="Button1_Click" /> 
            <telerik:RadGrid ID="RadGrid1" runat="server" DataSourceID="ObjectDataSource1" GridLines="None" 
                AllowFilteringByColumn="true" OnPreRender="RadGrid1_PreRender">  
                <MasterTableView AutoGenerateColumns="false" 
                FilterExpression="(Supervisor = 2)">  
                    <Columns> 
                        <telerik:GridBoundColumn DataField="LastName" HeaderText="LastName" UniqueName="LastName"></telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="FirstName" HeaderText="FirstName" UniqueName="FirstName"></telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Title" HeaderText="Title" UniqueName="Title"></telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Courtesy" HeaderText="Courtesy" UniqueName="Courtesy"></telerik:GridBoundColumn> 
                        <telerik:GridBoundColumn DataField="Supervisor" HeaderText="Supervisor" UniqueName="Supervisor"></telerik:GridBoundColumn> 
                    </Columns> 
                </MasterTableView> 
            </telerik:RadGrid> 
            <asp:ObjectDataSource ID="ObjectDataSource1" runat="server" SelectMethod="GetAllEmployees" 
                TypeName="EmployeeLogic" />              
        </div> 
    </form> 
</body> 
</html> 

 3. Comment out the code in RadGrid1_PreRender method because it threw the exception.

4. How to test:
a) Run project, by default it will show records with Supervisor =2  
b) Add filter LastName contain 'Pe', the only 1 record will be displayed
c) Click Rebind button - it will show records as in a) but preservs LastName filter value 'Pe'.

0
Iana Tsolova
Telerik team
answered on 07 Oct 2008, 10:49 AM
Hi miksh,

Thank you for your cooperation.

I suggest that you implement same scenario but binding the grid through the NeedDataSource and check if then the grid behaves as desired.

Please find more about RadGrid data-binding:
http://www.telerik.com/help/aspnet-ajax/grdadvanceddatabinding.html
http://www.telerik.com/help/aspnet-ajax/grddeclarativedatasource.html
http://www.telerik.com/help/aspnet-ajax/grddatabindingbasics.html

Best wishes,
Iana
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
0
miksh
Top achievements
Rank 1
Iron
answered on 07 Oct 2008, 02:40 PM
I opened the ticket 166224.
Tags
Grid
Asked by
Pratap
Top achievements
Rank 1
Answers by
miksh
Top achievements
Rank 1
Iron
Iana Tsolova
Telerik team
Share this question
or