RadGrid problem with filtering multiple columns

1 Answer 42 Views
Ajax Filter Grid
Nancy
Top achievements
Rank 1
Iron
Nancy asked on 15 Nov 2024, 01:03 AM

Hi, I have a RadGrid with AllowFilteringByColumn="True" and multiple columns with with the properties set up for filtering, like so:
AutoPostBackOnFilter="false" FilterControlWidth="100%" CurrentFilterFunction="StartsWith" ShowFilterIcon="false" FilterDelay="4000"

When I filter by 1 column, it works fine. Then I filter by an additional column, it works fine.

The problem seems to be when I clear those 2 column filters at the same time.  The first column that is cleared, retains the filter value.

Another option would be to only do the filter when the user hits <enter>.  After thinking about it, this may be the better choice, anyway, as it is more what the users are accustomed to.  I see a bunch of old answers on how to do this, but nothing very current.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Vasko
Telerik team
answered on 19 Nov 2024, 03:33 PM

Hi Nancy,

I hope you're doing well!

By the description of the issue, I suppose you are either using the logic from the Clear all filters in RadGrid article or a custom approach, can you confirm which one exactly?

I tested with the approach from the article and it works as expected, you can test with the below code sample:

<telerik:RadGrid ID="RadGrid1" runat="server" AllowFilteringByColumn="True" AllowPaging="True" DataSourceID="SqlDataSource1" Width="1000px">
    <MasterTableView DataSourceID="SqlDataSource1" AutoGenerateColumns="False"
        DataKeyNames="OrderID">
        <Columns>
            <telerik:GridBoundColumn DataField="OrderID" DataType="System.Int32"
                FilterControlAltText="Filter OrderID column" HeaderText="OrderID"
                ReadOnly="True" SortExpression="OrderID" UniqueName="OrderID">
            </telerik:GridBoundColumn>
            <telerik:GridDateTimeColumn DataField="OrderDate" DataType="System.DateTime"
                FilterControlAltText="Filter OrderDate column" HeaderText="OrderDate"
                SortExpression="OrderDate" UniqueName="OrderDate">
            </telerik:GridDateTimeColumn>
            <telerik:GridNumericColumn DataField="Freight" DataType="System.Decimal"
                FilterControlAltText="Filter Freight column" HeaderText="Freight"
                SortExpression="Freight" UniqueName="Freight">
            </telerik:GridNumericColumn>
            <telerik:GridBoundColumn DataField="ShipName"
                FilterControlAltText="Filter ShipName column" HeaderText="ShipName" AutoPostBackOnFilter="false" FilterControlWidth="100%" CurrentFilterFunction="StartsWith" ShowFilterIcon="false" FilterDelay="4000"
                SortExpression="ShipName" UniqueName="ShipName">
            </telerik:GridBoundColumn>
            <telerik:GridBoundColumn DataField="ShipCountry"
                FilterControlAltText="Filter ShipCountry column" HeaderText="ShipCountry" AutoPostBackOnFilter="false" FilterControlWidth="100%" CurrentFilterFunction="StartsWith" ShowFilterIcon="false" FilterDelay="4000"
                SortExpression="ShipCountry" UniqueName="ShipCountry">
            </telerik:GridBoundColumn>
        </Columns>
    </MasterTableView>
</telerik:RadGrid>

<telerik:RadButton runat="server" ID="RadButton_ClearAllFilters" AutoPostBack="true" Text="Clear all filters" OnClick="RadButton_ClearAllFilters_Click" />

<asp:SqlDataSource ID="SqlDataSource1" runat="server"
    ConnectionString="<%$ ConnectionStrings:NorthwindConnectionString %>"
    SelectCommand="SELECT [OrderID], [OrderDate], [Freight], [ShipName], [ShipCountry] FROM [Orders]"></asp:SqlDataSource>
protected void RadButton_ClearAllFilters_Click(object sender, EventArgs e)
{
    foreach (GridColumn column in RadGrid1.MasterTableView.Columns)
    {
        column.ListOfFilterValues = null; // CheckList values set to null will uncheck all the checkboxes

        column.CurrentFilterFunction = GridKnownFunction.NoFilter;
        column.AndCurrentFilterFunction = GridKnownFunction.NoFilter;

        column.CurrentFilterValue = string.Empty;
        column.AndCurrentFilterValue = string.Empty;
    }
    RadGrid1.MasterTableView.FilterExpression = string.Empty;
    RadGrid1.MasterTableView.Rebind();
}

    Try the above configuration with the approach from the article and see if it will help in your scenario.

    Regards,
    Vasko
    Progress Telerik

    Stay tuned by visiting our public roadmap and feedback portal pages! Or perhaps, if you are new to our Telerik family, check out our getting started resources
    Nancy
    Top achievements
    Rank 1
    Iron
    commented on 19 Nov 2024, 05:56 PM

    Thank you for your reply, Vasko.

    I had not seen that ClearAllFilters method.  I may implement it.  However, that isn't what I was trying to do.  Say there are 2 filters entered.  Then the user manually clears one of them, then the other.  This grid has multiple columns, so the user may only want to clear 1 column, not all of them.  The textbox for the first filter cleared does not clear / retains the value.

    Anyway, I think I fixed my own problem.  I compared with one of my other grids with the same kind of filter.  That grid uses GridTemplateColumn.  So I changed my troublesome grid from GridBoundColumn to GridTemplateColumn.  That has corrected the problem, though I don't know why!

    Vasko
    Telerik team
    commented on 20 Nov 2024, 09:25 AM

    Hi Nancy,

    It's great to hear that you were able to resolve the issue by switching from GridBoundColumn to GridTemplateColumn. Sometimes subtle differences in column types can have unexpected impacts, as you've observed.

    If you encounter any further questions or issues while working with your RadGrid, feel free to reach out by creating a new ticket. We're always here to help! 

    Regards,
    Vasko
    Progress Telerik

    Tags
    Ajax Filter Grid
    Asked by
    Nancy
    Top achievements
    Rank 1
    Iron
    Answers by
    Vasko
    Telerik team
    Share this question
    or