@foreach (var col in myGridCols){ <GridColumn [email protected] HeaderText="@col.HeaderText" ...}
This works fine, but i there is a situation with the ColumnChooser at unvisible columns by init. I searched for the cause and (maybe) found it. In combination of the parameters Width="auto" and Autofit="true" on a column that Visible=false, the ColumnChooser is not changing the visibilty of these columns. I tested these settings on your example project template in VS2019 and was able to reproduce the behavior.
<GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" IsPrimaryKey="true" Visible="false" ... width="auto" AutoFit="true"></GridColumn>
<GridColumn Field=@... Visible="true" width="auto" AutoFit="true"></GridColumn>
|
<SfGrid @ref="Grid" DataSource="@Employees" ShowColumnChooser="true" Toolbar=@ToolbarItems>
<GridEvents OnActionComplete="ActionComplete" TValue="EmployeeData"></GridEvents>
<GridColumns>
<GridColumn Field=@nameof(EmployeeData.EmployeeID) Visible="false" Width="auto" AutoFit="true" TextAlign="TextAlign.Center" HeaderText="Employee ID"></GridColumn>
<GridColumn Field=@nameof(EmployeeData.FirstName) HeaderText="First Name" ShowInColumnChooser="false" Width="130"></GridColumn>
<GridColumn Field=@nameof(EmployeeData.LastName) Visible="true" Width="auto" AutoFit="true" HeaderText="Last Name"></GridColumn>
<GridColumn Field=@nameof(EmployeeData.HireDate) HeaderText="Hire Date" Format="d" TextAlign="TextAlign.Right" Width="150"></GridColumn>
</GridColumns>
</SfGrid>
@code{
SfGrid<EmployeeData> Grid { get; set; }
public string[] ToolbarItems = new string[] { "ColumnChooser" };
public void ActionComplete(ActionEventArgs<EmployeeData> Args)
{
if (Args.RequestType == Syncfusion.Blazor.Grids.Action.ColumnState)
{
Grid.Refresh();
}
}
|
Dear Vignesh
Thanks for the explanation, it helps me a lot for a better understanding of the grid routines.
I helped myself to set the width (in background) automatically to an explizit value, when property Autofit was set to true. But your solution is also a great idea and it works also.
Thank you for your fast support
Regards
Stefan