So I'm having a bit of trouble with the @bind-Settings stuff on RadzenDataGrid. It seems that after I load the settings I saved (serialized) in my database, but after load, the "set" in your example seems to overwrite the saved settings. Is there a bug in my code I'm not seeing?
So: OnInit gets the grid settings from db, deserializes, and saves that to _settings, which isn't unlike your example using local storage.
That triggers the set
property and if value isn't equal (which it isn't because value is null before this, it'll set the settings to value - which is overwriting the data from the db and making a save changes)
DataGridSettings _settings;
public DataGridSettings Settings
{
get
{
return _settings;
}
set
{
if (_settings != value)
{
_settings = value;
InvokeAsync(SaveSettings);
}
}
}
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
await GetGridSettings();
}
async Task GetGridSettings()
{
try
{
using var scope = _serviceScopeFactory.CreateScope();
GridSettingsRepository repo = scope.ServiceProvider.GetRequiredService<GridSettingsRepository>();
_gridSettings = await repo.GetOneAsync(x => x.ModifiedById == _authService.LoggedInUserId && x.GridName == this.GetType().Name);
if (_gridSettings is not null && _gridSettings.Id > 0)
{
_settings = JsonSerializer.Deserialize<DataGridSettings>(_gridSettings.RadzenDataGridSettings);
}
await InvokeAsync(StateHasChanged);
}
catch (Exception ex)
{
_notificationService.Notify(new NotificationMessage
{
Severity = NotificationSeverity.Error,
Detail = "Unable to get settings."
});
_logger.LogError(ex.Message);
}
}
async Task SaveSettings()
{
try
{
using var scope = _serviceScopeFactory.CreateScope();
GridSettingsRepository repo = scope.ServiceProvider.GetRequiredService<GridSettingsRepository>();
if (_gridSettings is null)
{
}
else
{
_gridSettings.RadzenDataGridSettings = JsonSerializer.Serialize(_settings);
_gridSettings.ModifiedDate = DateTime.Now;
await repo.UpdateAsync(_gridSettings);
}
}
catch (Exception ex)
{
_notificationService.Notify(new NotificationMessage
{
Severity = NotificationSeverity.Error,
Detail = "Unable to save settings"
});
_logger.LogError(ex.Message);
}
}