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

Add filter programmatically

1 Answer 244 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Pierre
Top achievements
Rank 1
Pierre asked on 02 Sep 2016, 11:21 AM
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

1 Answer, 1 is accepted

Sort by
0
Kostadin
Telerik team
answered on 07 Sep 2016, 07:35 AM
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.
Tags
Grid
Asked by
Pierre
Top achievements
Rank 1
Answers by
Kostadin
Telerik team
Share this question
or