Hi, I have a problem with context menu column picker, I have copied code from demo and it's working fine with hard coded columns, but It's not picking auto generated columns from my code, they are populated in menu but not adding to table when I choose it. Classic dropdown column picker is working properly.
That's how my grid code looks:
<RadzenDataGrid @bind-Settings="@Settings" ContextMenu="@(args => ShowColumnPicker(args))" IsLoading="isLoading" @ref="grid" TItem="TItem" LoadData="LoadData" Data="records" Count="count" AllowColumnPicking="true" AllowFiltering="true" RowDoubleClick="@(args => RowDoubleClick(args.Data))">
<HeaderTemplate>
<RadzenStack Orientation="Orientation.Horizontal" AlignItems="AlignItems.Stretch" Style="width: 500px">
<RadzenRow Style="width: 500px">
<RadzenColumn Size="12" Style="border: dashed 1px">
<div class="btn-group" role="group" aria-label="Basic mixed styles example">
<button type="button" @onclick="@(() => AddRecordAsync(String.IsNullOrEmpty(FormTitle) ? "Nowy rekord" : FormTitle, null, null))" class="@(AllowAdd ? "btn btn-outline-success border-0" : "btn btn-outline-secondary border-0 disabled")"><RadzenIcon Icon="add_circle" Style="width: 100%; height: 100%" /></button>
<button type="button" @onclick="@(() => grid.Reload())" class="btn btn-outline-primary border-0"><RadzenIcon Icon="cached" Style="width: 100%; height: 100%" /></button>
<button type="button" @onclick="@(args => ShowColumnPicker(args))" class="btn btn-outline-primary border-0"><RadzenIcon Icon="view_column" Style="width: 100%; height: 100%" /> </button>
</div>
</RadzenColumn>
</RadzenRow>
</RadzenStack>
</HeaderTemplate>
<Columns>
@ChildContent(default)
@Columns
<RadzenDataGridColumn Pickable="false" Width="64px" Filterable="false" Sortable="false" TextAlign="TextAlign.Center" Frozen="true" FrozenPosition="FrozenColumnPosition.Right">
<Template Context="context">
<RadzenButton Icon="more_vert" ButtonStyle="ButtonStyle.Light" Variant="Variant.Flat" Click="@(args => ShowContextMenuWithItems(args, context))">
</RadzenButton>
</Template>
</RadzenDataGridColumn>
</Columns>
</RadzenDataGrid>
And there is code which populate Columns variable, it's designed to populate all properties from TItem:
protected override async Task OnAfterRenderAsync(bool firstRender)
{
if (firstRender)
{
var resourceManager = new ResourceManager(typeof(TItem));
bool _missingResource = false;
try
{
// Attempt to load the resource set for the "pl-PL" culture
resourceManager.GetResourceSet(new CultureInfo("pl-PL"), true, true);
}
catch (MissingManifestResourceException)
{
_missingResource = true; // Mark that the resource was missing
}
var properties = typeof(TItem).GetProperties();
// Create RenderFragment dynamically
Columns = builder =>
{
int seq = 0; // Sequence counter for RenderFragment
foreach (var propertyInfo in properties)
{
string? translatedName = null;
if (!_missingResource)
{
translatedName = resourceManager.GetString(propertyInfo.Name);
}
// Add RadzenDataGridColumn dynamically
builder.OpenComponent<RadzenDataGridColumn<TItem>>(seq++);
builder.AddAttribute(seq++, "Property", propertyInfo.Name);
builder.AddAttribute(seq++, "Title", string.IsNullOrEmpty(translatedName) ? propertyInfo.Name : translatedName);
builder.AddAttribute(seq++, "Visible", false);
builder.AddAttribute(seq++, "Pickable", true);
builder.CloseComponent();
}
};
//await LoadStateAsync();
}
}