JavaScript UI Libraries & Blazor Components Suite – Smart UI › Forums › Data Grid › Dynamic columns (Blazor) › Reply To: Dynamic columns (Blazor)
Another question from the example I mentioned above (GridDynamicColumsPage)
I didn’t understand the line in
private void AddColumn()
{
…..
grid.Columns = new List<GridColumn>() { }; //TODO: remove
….
}
When you comment out the line, now column will be added, but it should because of parameter binding.
<Grid @ref=”grid” DataSource=”dataRecords” Columns=”@columns”></Grid>
With this workaround you also lost some settings
e.g.
<Grid @ref=”grid” DataSource=”dataRecords” Columns=”@columns” Sorting=”@sorting”></Grid>
GridSorting sorting = new GridSorting { Enabled = true };
private void AddColumn()
{
GridColumn newColumn = new GridColumn(){ Label = columnsList[i], DataField = columnsList[i], SortOrder = GridColumnSortOrder.Desc };
columns.Add(newColumn);
grid.Columns = new List<GridColumn>() { }; //TODO: remove
}
This will add the column, but the sort order get lost.