# Change the Grid Filter Mode at Runtime

## Environment

<table>
    <tbody>
        <tr>
            <td>Product</td>
            <td>Grid for Blazor</td>
        </tr>
        <tr>
            <td>Version</td>
            <td>15.0.1 and above</td>
        </tr>
    </tbody>
</table>

## Description

How to change the Grid `FilterMode` at runtime?

This KB also answers the following question:

* How to disable filtering and show the filter row or filter menu again?

## Solution

Set the Grid `FilterMode` parameter to one of the following values:

1. Set `FilterMode` to `GridFilterMode.None` to hide the filtering UI.
2. Set `FilterMode` to `GridFilterMode.FilterRow` to display a filter row below the column headers.
3. Set `FilterMode` to `GridFilterMode.FilterMenu` to display a filter button in the column headers.

When you change the filter mode at runtime, recreate the Grid so that it rebuilds the columns and filter templates. Use a render flag around the Grid, update the filter mode, and render the Grid again.

The following example demonstrates how to recreate the Grid after changing the filter mode:

> caption Change the Grid FilterMode at runtime

```RAZOR
@if (ShowGrid)
{
    <TelerikGrid Data="@GridData"
                 FilterMode="@CurrentFilterMode">
        <GridColumns>
            <GridColumn Field="@nameof(Product.Name)" />
        </GridColumns>
    </TelerikGrid>
}

<TelerikButton OnClick="@(() => ChangeFilterMode(GridFilterMode.None))">
    Disable Filtering
</TelerikButton>
<TelerikButton OnClick="@(() => ChangeFilterMode(GridFilterMode.FilterRow))">
    Show Filter Row
</TelerikButton>
<TelerikButton OnClick="@(() => ChangeFilterMode(GridFilterMode.FilterMenu))">
    Show Filter Menu
</TelerikButton>

@code {
    private bool ShowGrid { get; set; } = true;
    private GridFilterMode CurrentFilterMode { get; set; } = GridFilterMode.FilterMenu;

    private async Task ChangeFilterMode(GridFilterMode newFilterMode)
    {
        ShowGrid = false;
        await Task.Delay(100);

        CurrentFilterMode = newFilterMode;
        ShowGrid = true;
    }

    private List<Product> GridData { get; set; } = new();

    private class Product
    {
        public string Name { get; set; } = string.Empty;
    }
}
```

This approach recreates the Grid after each filter mode change. If you also use Grid state, save the state before recreation and restore the applicable state after the Grid renders again. For more information, refer to the [Grid state](https://www.telerik.com/blazor-ui/documentation/components/grid/state) documentation.

## See Also

* [Grid Filtering Overview](https://www.telerik.com/blazor-ui/documentation/components/grid/filter/overview)
* [Grid Filter Row](https://www.telerik.com/blazor-ui/documentation/components/grid/filter/filter-row)
* [Grid Filter Menu](https://www.telerik.com/blazor-ui/documentation/components/grid/filter/filter-menu)
