I have a component which some standard columns I want in most of my tables. It takes a @ChildContent which defines specific columns to display in the grid. It looks like this:
<RadzenGrid TItem="TRecord"
RowSelect="RowSelected">
<Columns>
@if (ShowEditButtons)
{
@*A column that goes at the beginning and defines some buttons*@
}
@ChildContent
@*Some columns that go at the end*@
</Columns>
</RadzenGrid>
This allows some flexibility to show/hide columns as needed. I have found that when the user toggles ShowEditButtons to True or if they add columns to @ChildContent, both of which add a new column to the grid, that the new column will end up at the end of the grid instead of the intended position.
I assume this is because the new RadzenGridColumn which is being rendered is just added a list of columns, and is at the end. I think it would be great if there was an optional parameter for ColumnOrder which I could specify.
I did try toggling Visible from false to true, or changing Width from 0rem to something longer as options to show or hide columns. That worked OK on the cells of the column, but the header wouldn't show up.
Hi @enchev, @mconrad.
Problem with column order is due blazor optimization in BuildRenderTree.
To avoid rewrite BlazorGrid twice, One solution could be create a new component with only Datagrid with all columns using @if (showColumns) and showColumns as parameter.
And in Parent do:
Both of these make sense as work around for the simple example I showed. I don't think they can solve the issue where I am changing the ChildContent columns. @ctnet I'm not sure if I tried this option exactly, but I was thinking the option of last resort might be to force blazor to make a new component no matter what when this changed.
I think if Visible worked as expected (so that the column header showed/hid with the columns) or if there was a new parameter for column order, then I think I could handle the ChildContent columns as well.
Finally have a solution: As @ctnet pointed out this issue was happening because of how blender optimizes render tree building.
I realized we can use the @key directive by binding it to the record ID that was populating my grid. Then when the record changed, blazor will see the @key change and dump and rebuild the grid from scratch.