Modify filter value in Datagrid

Hi,

Is it possible to change the filter value after the user has entered it, but before the filter is applied?

I need to remove some special characters from the value if they exist.

With best regards
Søren

Yes, you can use LoadData to apply custom filtering, process filter values, etc:

Thanks,

If I change a filter value on a filter in LoadDataArgs, is there a way I can recreate the LoadDataArgs.Filter string to match the updated filter?

Or is there another way to update and use a filter value in LoadData?

/Søren

The official way of save/load filters with LoadData is demonstrated here:

1 Like

I tried to make it happen like below however it doesn't work.

Debugged it and '(_settings != value)';
'_settings' always equal to latest settings
'value' always equals to default one.

Thats why its always resetting to default one. What could be the reason?

<RadzenDataGrid @bind-Settings="@Settings" Style="height: 82vh" TItem="Lists.list_Sessions" Data="@listSessions">

@code
DataGridSettings _settings;
public DataGridSettings Settings
{
    get
    {
        return _settings;
    }
    set
    {
        if (_settings != value)
        {
            _settings = value;
            InvokeAsync(SaveStateAsync);
        }
    }
}

private async Task LoadStateAsync()
{
    await Task.CompletedTask;

    var result = await JSRuntime.InvokeAsync<string>("window.localStorage.getItem", "Settings");
    if (!string.IsNullOrEmpty(result))
    {
        _settings = JsonSerializer.Deserialize<DataGridSettings>(result);
    }
}

private async Task SaveStateAsync()
{
    await Task.CompletedTask;

    await JSRuntime.InvokeVoidAsync("window.localStorage.setItem", "Settings", JsonSerializer.Serialize<DataGridSettings>(Settings));
}

Try to run and debug our demo to check what’s the difference with your implementation.

Realized that below part is being called twice.

first call it works as intended and second call resets to default settings.

After all i found that Grid re-renders because of data/gridsettings has been updated and after re-rendering it gets default values. This seems like a bug.

set
    {
        if (_settings != value)
        {
            _settings = value;
            InvokeAsync(SaveStateAsync);
        }
    }

Let us know how to reproduce it in our demo.