How to fully reset a column filter in FlexGrid?

Posted by: mhillen on 8 May 2023, 7:31 am EST

    • Post Options:
    • Link

    Posted 8 May 2023, 7:31 am EST - Updated 8 May 2023, 9:04 am EST

    Hi,

    I have the following problem:

    1. I can manually filter he column by Text or by Value

    2. Ber Button click I apply a column filter to that column within the code like

    ConditionFilter filterNoAtc = new ConditionFilter();
                filterNoAtc.Condition1.Operator = ConditionOperator.DoesNotContain;
                filterNoAtc.Condition1.Parameter = "ATC";
    flexGridActualInspects.Cols["ATC_NR"].Filter = filterNoAtc;
    flexGridActualInspects.ApplyFilters();

    1. Then I clear the filter in code like
    flexGridActualInspects.ClearFilter();

    or

    flexGridActualInspects.FilterDefinition = "<ColumnFilters />";
    1. When I now want to filter manually again, I can not switch between TextFilter and ValueFilter like before I applied the filter (Step 2).

    Is there another way to clear the filters so both filter methods are working again?

    I’m using Version 4.8.20231.596

    I attached 3 screenshots showing the steps and to visualize what I mean.

    Any help is appreciated.

    Regards…Michael

  • Posted 9 May 2023, 12:23 am EST

    Hi Michael,

    The Filtering dropdown of a column only shows the Filter option that is assigned to the Filter property of that column. If a ValueFilter or a ConditionFilter object is assigned to a Column, and you call the ClearFilter method, then the filter dropdown won’t show both filter options again. This is because the ClearFilter method only resets the Filter objects and does not remove them from the Columns.

    To get back both the Filter options in the filter dropdown, you will need to set the Column.Filter property back to null. Please see the attached sample project for reference.

    Attachment: ClearFiltering.FlexGrid.zip

    Thanks, and Best Regards,

    Kartik

  • Posted 9 May 2023, 2:21 am EST

    Hi Kartik,

    I tried several things but not setting to null :slight_smile:

    It is working now by setting the Filter for all columns to null after calling ClearFilter().

    Thank you for your quick answer.

    Regards…Michael

  • Posted 9 May 2023, 3:37 am EST

    Hi Michael,

    We are happy to know that your issue is resolved. You can even skip calling the ClearFilter method and directly assign the null value to the Filter property of all columns. This automatically clears the filtering.

    Best Regards,

    Kartik

  • Posted 9 May 2023, 6:02 am EST

    Hi Kartik,

    I already tried that. But then the filter is still active and even the filter icon in the column (the checkmark showing that filter is active) is still visible after setting Filter to null.

    When I then hover the mouse of the filter icon it disappears but the filter remains active. That’s the reason why I kept the ClearFilter() method.

    But this is only true for filters set programmatically.

    If I set the filter manually, then it’s just okay to set Filter to null without calling ClearFilter().

    For me it’s fine now but if you want to dig deeper, let me know.

    Unfortunately it seems that I can’t provide a video here and I’m not able to quickly share only a part of the source code.

    Regards…Michael

  • Posted 10 May 2023, 12:08 am EST

    Hi Michael,

    We tested the scenario in the sample project we shared and observed that setting the Column.Filter to null clears the filtering automatically. Nevertheless, since it is working fine on your end now, you can continue to work with it your way. If you face any issues in the future or if you need any other information, you can let us know anytime.

    Thanks, and Kind Regards,

    Kartik

  • Posted 10 May 2023, 2:33 am EST

    Now I found my problem.

    I parsed the FlexGrid from the SourceControl of a ContextMenu

    C1FlexGrid fg = (C1FlexGrid)contextMenuStripFG.SourceControl;
    foreach (Column col in fg.Cols)
    {
    	col.Filter = null;
    }


    Using this fg object to set Filter to null lead to the problem.

    Using instead

    foreach (Column col in ((C1FlexGrid)contextMenuStripFG.SourceControl).Cols)
    {
    	col.Filter = null;
    }


    did the job without calling ClearFilter()

    Just for you information that this one is now also cleared out :slight_smile:

  • Posted 10 May 2023, 4:24 am EST

    Hi Michael,

    Thanks for letting us know. We are glad your issue is now resolved. If you need any other information, you can let us know.

    Kind Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels