Hi there,
I'm having some trouble implementing the solution outlined in the demo at Blazor DataGrid Component - Save / Load Settings | Free UI Components by Radzen...
I am trying to get my datagrid to remember its filters when I navigate away from and then back to the page containing it. I am debugging and inspecting the Settings object which remembers my custom filter text, but the text is not actually manifesting on the screen in the filter text bar. Any reason why this might be happening? Here is my code:
<RadzenDataGrid Data="@(_cohorts.Where(c => c.Template.Type == type))"
TItem="DbTemplateTable"
@ref=@_cohortGrid
@bind-Settings="@Settings"
AllowFiltering="true"
IsLoading="@_cohortDataLoading"
FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive"
FilterMode="FilterMode.SimpleWithMenu"
AllowSorting="true"
AllowColumnResize="true"
SelectionMode="DataGridSelectionMode.Multiple"
@bind-Value="@_selectedCohorts"
RowSelect="RowSelected"
RowDeselect="RowDeselected"
AllowVirtualization="true"
Style="@DataTableStyle">
{columns etc....}
DataGridSettings _settings;
public DataGridSettings Settings
{
get
{
return _settings;
}
set
{
if (_settings != value)
{
_settings = value;
InvokeAsync(SaveStateAsync);
}
}
}protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
await LoadStateAsync();
StateHasChanged();
}
}
private async Task LoadStateAsync()
{
await Task.CompletedTask;
var result = await JSRuntime.InvokeAsync<string>("window.localStorage.getItem", "Settings");
if (!string.IsNullOrEmpty(result))
{
try
{
_settings = JsonSerializer.Deserialize<DataGridSettings>(result);
}
catch (JsonException)
{
_settings = new DataGridSettings();
}
}
}
private async Task SaveStateAsync()
{
await Task.CompletedTask;
await JSRuntime.InvokeVoidAsync("window.localStorage.setItem", "Settings", JsonSerializer.Serialize<DataGridSettings>(Settings));
}