Add filter programmatically

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

    Posted 02 Sep Link to this post

    Hi,

    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>
     
        <CommandItemTemplate>
            <telerik:RadButton ID="RadButton1" runat="server" Text="ClearFilter" CommandName="ClearFilter" OnClick="ClearFilter">
            <Icon PrimaryIconCssClass="rbCancel" />
            </telerik:RadButton>
     
            <telerik:RadButton ID="RadButton2" runat="server" Text="++++++++++++++" CommandName="Exp"  OnClick="CustomFilter">
            </telerik:RadButton>
     
            <telerik:RadButton ID="RadButton3" runat="server" Text="---------------" CommandName="No-Exp" OnClick="CustomFilter2">
            </telerik:RadButton>
        </CommandItemTemplate>
     
        <Columns>
            <telerik:GridTemplateColumn DataField="totaldone" HeaderText="totaldone" UniqueName="SuperFilter" >
            [...]
            </telerik:GridTemplateColumn>
        </Columns>

    With in my code behind:
    protected void CustomFilter(object sender, EventArgs e)
    {
        dude(RG_BL.MasterTableView);
    }
    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";
                        }
                    }
                    nestedView.Rebind();
                }
                if (nestedView.HasDetailTables)
                { dude(nestedView); }
            }
        }
    }

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

    Regards,
    Pierre
  2. Kostadin
    Admin
    Kostadin avatar
    1711 posts

    Posted 07 Sep 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

    Regards,
    Kostadin
    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.
  3. UI for ASP.NET Ajax is Ready for VS 2017
Back to Top