I have a RadzenDataGrid with several columns. The settings are saved using the @bind-Settings setting.
Most of the column settings are saved correctly, but not all columns. I have an “actions” column with a few buttons that is not tied to a Property and this column cannot be hidden because it will not appear in the settings.Columns list.
If I set the Property field of the column, then the column will appear in the settings.Columns list. But it looks strange to set a Property on a column that isn’t used in the column.
Is this functionality by design or am I doing something incorrectly?
I also can reproduce the problem using the demo:
@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore
@inherits DbContextPage
<RadzenDataGrid
Data="@employees"
TItem="Employee"
AllowFiltering=true
ColumnWidth="300px"
AllowColumnPicking="true"
ColumnsPickerAllowFiltering="true"
@bind-Settings="@Settings"
>
<Columns>
<RadzenDataGridColumn
Property=@nameof(Employee.EmployeeID)
Title="ID"
Width="80px"
TextAlign="TextAlign.Center"
Frozen="true" />
<RadzenDataGridColumn Title="Photo" Sortable="false" Width="200px" Pickable="false">
<Template Context="data">
<RadzenImage Path="@data.Photo" class="rz-gravatar" AlternateText="@(data.FirstName + " " + data.LastName)" />
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn Property=@nameof(Employee.FirstName) Title="First Name" />
<RadzenDataGridColumn Property=@nameof(Employee.LastName) Title="Last Name" Width="150px"/>
<RadzenDataGridColumn Property=@nameof(Employee.Title) Title="Title" />
<RadzenDataGridColumn Property=@nameof(Employee.TitleOfCourtesy) Title="Title Of Courtesy" />
<RadzenDataGridColumn Property=@nameof(Employee.BirthDate) Title="Birth Date" FormatString="{0:d}" />
<RadzenDataGridColumn Property=@nameof(Employee.HireDate) Title="Hire Date" FormatString="{0:d}" />
<RadzenDataGridColumn Property=@nameof(Employee.Address) Title="Address" />
<RadzenDataGridColumn Property=@nameof(Employee.City) Title="City" />
<RadzenDataGridColumn Property=@nameof(Employee.Region) Title="Region" />
<RadzenDataGridColumn Property=@nameof(Employee.PostalCode) Title="Postal Code" />
<RadzenDataGridColumn Property=@nameof(Employee.Country) Title="Country" />
<RadzenDataGridColumn Property=@nameof(Employee.HomePhone) Title="Home Phone" />
<RadzenDataGridColumn Property=@nameof(Employee.Extension) Title="Extension" ColumnPickerTitle="Phone Number Extension" />
<RadzenDataGridColumn Property=@nameof(Employee.Notes) Title="Notes" />
<RadzenDataGridColumn TItem="Employee" Title="Actions1" Property="Bla">
<Template Context="item"><span>@item.Notes</span></Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn Title="Actions2">
<Template><span>test</span></Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn Title="Actions3">
<Template><span>test</span></Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
<EventConsole @ref=@console />
@code {
IEnumerable<Employee> employees;
EventConsole console;
private DataGridSettings _settings;
public DataGridSettings Settings
{
get => _settings;
set
{
foreach (var column in value.Columns)
{
console.Log(column.UniqueID);
}
_settings = value;
}
}
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
employees = dbContext.Employees;
}
/// <summary>
/// Only used to print the changes to the console.
/// </summary>
void PickedColumnsChanged(DataGridPickedColumnsChangedEventArgs<Employee> args)
{
console.Log($"Picked columns: {string.Join(", ", args.Columns.Select(c => c.Title))}");
}
}