I have a working solution for saving columns in a DataGrid, but I cant set the PickedColumnsChanged handler properly without doing the below, which does work
<RadzenDataGrid @ref=dataGrid PickedColumnsChanged="@(EventCallback.Factory.Create<DataGridPickedColumnsChangedEventArgs<CurrentRuleRow>>(this, OnPickedColumnsChanged))" AllowPickAllColumns=true AllowColumnPicking="true"
AllowSorting="true" PageSize="20" AllowPaging="true" PagerHorizontalAlign="HorizontalAlign.Center" PagerPosition="PagerPosition.Bottom"
Data=@Result.Rules LogicalFilterOperator="LogicalFilterOperator.Or" SelectionMode="DataGridSelectionMode.Single">
and handler
async Task OnPickedColumnsChanged(DataGridPickedColumnsChangedEventArgs<CurrentRuleRow> args)
{
activeColumns = args.Columns.Select(x => x.Title).ToList();
await localStorage.SetItemAsync<List<string>>(Constants.CurrentRuleColumns, activeColumns);
}
I above does work but its ugly, and feels wrong.
if I set it like I see in lots of examples I get this build error in VS2022
PickedColumnsChanged="@OnPickedColumnsChanged"
Argument 2: cannot convert from 'method group' to 'Microsoft.AspNetCore.Components.EventCallback'
Issue no2 is that im loading the columns like this
async Task SetColumns()
{
activeColumns = await localStorage.GetItemAsync<List<string>>(Constants.CurrentRuleColumns);
if (activeColumns == null)
return;
foreach (var col in dataGrid.ColumnsCollection)
{
col.Visible = activeColumns.Any(x => col.Title == x);
}
}
which works, but I get a warning about not setting visible outside of its component, all works fine though.
Is there any working example of how to do this "correctly" ? This is in .Net 9