Show active filters in grid header

Hello,

is there any way to display the active filtered values in the grid header? An example is this grid:  datatable - Google Material Design - Complex Conditional Filtering Chips in  Filter Bar in Data Tables - Stack Overflow

where we can see offline signals and lapsed time >= 10min which are the current active filters for this grid.

Furthermore, is it possible to have a 'x' icon in the bubbles and a "clear all filters" button that provide the option to clear the filters?

Krasimir


5 Replies

PS Prathap Senthil Syncfusion Team June 19, 2023 11:37 AM UTC

Hi Krasimir,

Based on your requirement, we recommend using the default filtering option for the Filter Bar type in the Blazor DataGrid. With this approach, the filtered values will be displayed in the pager within the grid. You can refer to the attached online demo for your reference.


Demo sample: Blazor DataGrid Default Filtering Example - Syncfusion Demos

Additionally, if you want to clear the filter using a button click, we suggest utilizing the grid public method ClearFilterAsync(). This method allows you to programmatically remove any applied filters.

https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_ClearFilteringAsync

Regards,
Prathap S



KI Krasimir Ivanov June 19, 2023 08:52 PM UTC

Hi Prathap,


thank you for the response. This works but is there any way to do it while using FilterType.Menu?


Krasimir



PS Prathap Senthil Syncfusion Team June 20, 2023 09:00 AM UTC

Thanks for the update,

After reviewing your request, we have identified a possible solution that addresses your requirement. We recommend utilizing the OnActionComplete event argument to check for the RequestType "filtering” and stored the filter field and value  FilterValues dictionary property. By implementing this approach, you will be able to display the filter values outside of the grid.

To assist you further, we have prepared a sample application and included a code snippet for your reference.


@using Syncfusion.Blazor.Grids

@if (FilterValues != null)

{

    <div>

        @foreach (var data in FilterValues)

        {

            <span>@data.Key : @data.Value; </span>

        }

    </div>

}

<SfGrid @ref="Grid" TValue="Order" DataSource="@Orders" AllowFiltering="true" AllowPaging="true" Height="315">

    <GridEvents OnActionComplete="ActionCompletedHandler" TValue="Order"></GridEvents>

</SfGrid>

 

@code {

   

    public Dictionary<string, object> FilterValues { get; set; } = new Dictionary<string, object>();

 

    public void ActionCompletedHandler(ActionEventArgs<Order> args)

    {

        if (args.RequestType == Syncfusion.Blazor.Grids.Action.Filtering)

        {

            if (args.CurrentFilterObject?.ActualValue != null && !(FilterValues.ContainsKey(args.CurrentFilterObject?.Field)))

            {

                FilterValues.Add(args.CurrentFilterObject.Field, args.CurrentFilterObject.ActualValue); //Stored the filter fields and values

            }

            else if (FilterValues.Count != 0 && args.CurrentFilterObject?.ActualValue == null)

            {

                FilterValues?.Remove(args.CurrentFilterObject?.Field); //Remove filtered field and value on clear button click in the filter menu.

            }

 

        }

 

    }

}
A picture containing text, line, font, number

Description automatically generated



Attachment: DataGrid.._3bf583c6.zip


CM Charles Matvchuk April 3, 2024 01:54 AM UTC

This solution doesn't appear to work when using excel like filtering.  How can I do the same thing?



PS Prathap Senthil Syncfusion Team April 3, 2024 11:43 AM UTC

Hi Charles,

Based on your requirements for using the Excel-like filter, we regret to inform you that it is not feasible to meet your needs. Thank you for your understanding.

Regards,
Prathap S


Loader.
Up arrow icon