Add filter programmatically

2 posts, 0 answers
  1. Pierre
    Pierre avatar
    58 posts
    Member since:
    Jun 2016

    Posted 02 Sep 2016 Link to this post


    I am trying to implement 3 buttons to filter a templated column in a nested grid.
    So i have my buttons. I can find the column. I had the filter. I rebind .. but No filter is apply .
    <telerik:GridTableView  runat="server" DataSourceID="LDS" Name="PRD" AutoGenerateColumns="False" DataKeyNames="1,2,3"
        ShowHeader="false" HierarchyDefaultExpanded="true"  CommandItemDisplay="Top" >
        <ParentTableRelation> [...] </ParentTableRelation>
            <telerik:RadButton ID="RadButton1" runat="server" Text="ClearFilter" CommandName="ClearFilter" OnClick="ClearFilter">
            <Icon PrimaryIconCssClass="rbCancel" />
            <telerik:RadButton ID="RadButton2" runat="server" Text="++++++++++++++" CommandName="Exp"  OnClick="CustomFilter">
            <telerik:RadButton ID="RadButton3" runat="server" Text="---------------" CommandName="No-Exp" OnClick="CustomFilter2">
            <telerik:GridTemplateColumn DataField="totaldone" HeaderText="totaldone" UniqueName="SuperFilter" >

    With in my code behind:
    protected void CustomFilter(object sender, EventArgs e)
    protected void dude(GridTableView gridTableView)
        GridItem[] nestedViewItems = gridTableView.GetItems(GridItemType.NestedView);
        foreach (GridNestedViewItem nestedViewItem in nestedViewItems)
        {// Let's find the grid
            foreach (GridTableView nestedView in nestedViewItem.NestedTableViews)
                this.Label1.Text += nestedView.Name + "(" + nestedView.Items.Count + ")" + " | ";
                if (nestedView.Name == "PRD")
                {// Got the Grid
                    nestedView.FilterExpression = string.Empty;
                    foreach (GridColumn column in nestedView.Columns)
                    {// The Column ?
                        if (column is GridTemplateColumn && column.UniqueName == "SuperFilter")
                        {// Here.
                            GridTemplateColumn myColumn = column as GridTemplateColumn;
                            myColumn.CurrentFilterFunction = GridKnownFunction.GreaterThan;
                            myColumn.CurrentFilterValue = "0";
                if (nestedView.HasDetailTables)
                { dude(nestedView); }

    I must have miss Something, If you have any idea.

  2. Kostadin
    Kostadin avatar
    1733 posts

    Posted 07 Sep 2016 Link to this post

    Hello Pierre,

    I examined the provided code and I noticed that you did not set a FilterExpression in your case. Keep in mind you need to apply the filter expression as well in order to filter the grid datasource. I would recommend you to examine the following help articles which elaborate more on this matter.

    Setting the initial filter in the code-behind
    Operate with the FilterExpression Manually

    Telerik by Progress
    Do you need help with upgrading your ASP.NET AJAX, WPF or WinForms projects? Check the Telerik API Analyzer and share your thoughts.
Back to Top