When a RadzenDataGridColumn
is only rendered if a condition is met and on first render this condition is not met, it appears at the wrong position, once the condition is met.
To clarify, I updated the sample page code. Please see below. Simply paste the new code there and run it. I added a button "Add column" and I added this column directly to the right of the title column. But it appears rightmost.
In my real project, I tried _dataGrid.Reload()
but that did not do the trick. Is there a way to get the new column at the desired position?
Thanks
Philipp
@using Radzen
@using RadzenBlazorDemos.Data
@using RadzenBlazorDemos.Models.Northwind
@using Microsoft.EntityFrameworkCore
@inherits DbContextPage
<div style="display: flex; align-items: center; margin-bottom: 16px">
<RadzenButton Click="@ClearSelection" Text="Clear Selection" />
<RadzenButton Click="@AddColumn" Text="Add column" />
@if (selectedEmployees?.Any() == true)
{
<div style="margin-left: 16px">
Selected Employee: @selectedEmployees[0].FirstName @selectedEmployees[0].LastName
</div>
}
</div>
<RadzenDataGrid AllowFiltering="true" FilterPopupRenderMode="PopupRenderMode.OnDemand" FilterCaseSensitivity="FilterCaseSensitivity.CaseInsensitive" AllowPaging="true" PageSize="4"
AllowSorting="true" Data="@employees" TItem="Employee" ColumnWidth="200px"
SelectionMode="DataGridSelectionMode.Single" @bind-Value=@selectedEmployees>
<Columns>
<RadzenDataGridColumn TItem="Employee" Property="Photo" Title="Employee" Sortable="false" Filterable="false">
<Template Context="data">
<RadzenImage Path="@data.Photo" style="width: 40px; height: 40px; border-radius: 8px; margin-right: 8px;" />
@data.FirstName @data.LastName
</Template>
</RadzenDataGridColumn>
<RadzenDataGridColumn TItem="Employee" Property="Title" Title="Title" />
@if (_foo)
{
<RadzenDataGridColumn TItem="Employee" Property="Title" Title="Test" />
}
<RadzenDataGridColumn TItem="Employee" Property="EmployeeID" Title="Employee ID" />
<RadzenDataGridColumn TItem="Employee" Property="HireDate" Title="Hire Date" FormatString="{0:d}" />
<RadzenDataGridColumn TItem="Employee" Property="City" Title="City" />
<RadzenDataGridColumn TItem="Employee" Property="Country" Title="Country" />
</Columns>
</RadzenDataGrid>
@code {
IEnumerable<Employee> employees;
IList<Employee> selectedEmployees;
bool _foo = false;
void ClearSelection()
{
selectedEmployees = null;
}
void AddColumn()
{
_foo = true;
}
protected override async Task OnInitializedAsync()
{
await base.OnInitializedAsync();
employees = dbContext.Employees;
selectedEmployees = employees.Take(1).ToList();
}
}