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

Initial Filtering on Grid not firing

2 Answers 119 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Jako
Top achievements
Rank 1
Jako asked on 24 Jan 2013, 10:32 AM
Hi there

I am using the Advanced Data Binding on a grid and want to set the initial filter. It is showing the text, but its not limiting the results as expected. If I filter after a page load, it does work though. I have also tried filtering with the PreRender event, but that doesn't work.
Here is my ASPX
<telerik:RadGrid ID="uxBookOrderGrid" runat="server" AutoGenerateColumns="false" OnNeedDataSource="uxBookOrderGrid_NeedDataSource"
        AllowPaging="true" PageSize="10" Width="95%"
        AllowFilteringByColumn="true"
        EnableLinqExpressions="false" AllowSorting="true" >
    <MasterTableView DataKeyNames="BookOrderID">
        <Columns>
            <telerik:GridBoundColumn FilterControlWidth="90%" SortExpression="StatusDescription" HeaderText="Status" DataField="StatusDescription" UniqueName="StatusDescription" CurrentFilterFunction="Contains" ShowFilterIcon="false" AutoPostBackOnFilter="true" />
        </Columns>    
        <NoRecordsTemplate>
            No Book Orders waiting to be Approved.
        </NoRecordsTemplate>              
    </MasterTableView>
</telerik:RadGrid>
and here is the code behind
protected void uxBookOrderGrid_NeedDataSource(object sender, GridNeedDataSourceEventArgs e)
{
    /// <summary>
    /// Fill Grid with all Book Orders that needs to be Approved
    /// </summary>
 
    uxBookOrderGrid.DataSource = SATextBooksUJ.Data.BookOrder.GetBookOrderListForAcquisition(acquisitions.UserID);
 
    if (!IsPostBack)
    {
        uxBookOrderGrid.MasterTableView.FilterExpression = "([StatusDescription] LIKE=\'%Approved by Departmental Approver%\')";
        GridColumn statusColumn = uxBookOrderGrid.MasterTableView.GetColumnSafe("StatusDescription");
        statusColumn.CurrentFilterFunction = GridKnownFunction.Contains;
        statusColumn.CurrentFilterValue = "Approved by Departmental Approver";
    }
}
Any ideas?

Thank you

2 Answers, 1 is accepted

Sort by
0
Princy
Top achievements
Rank 2
answered on 24 Jan 2013, 11:53 AM
Hi,

Try rebinding the grid in order to apply filter on initial load.
C#:
protected void RadGrid1_PreRender(object sender, System.EventArgs e)
{
    if (!Page.IsPostBack)
    {
        RadGrid1.MasterTableView.FilterExpression = "([Country] LIKE \'%Germany%\') ";
       . . .
        RadGrid1.MasterTableView.Rebind();
    }
}

Thanks,
Princy
0
Jako
Top achievements
Rank 1
answered on 24 Jan 2013, 11:56 AM
I will try and revert back to the PreRender Method and see if it works.
Tags
Grid
Asked by
Jako
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Jako
Top achievements
Rank 1
Share this question
or