What is the method for full Grid refresh including Header?

On my site I created grid which consists of different columns depending on data. Plus user is able to add new columns.
How I can refresh the whole grid after this?
Usually header stays the same.
I tried to update data source and
            await Grid.RefreshColumns();
            await Grid.RefreshHeader();
but it has not wished effect.

1 Reply 1 reply marked as answer

KM Kuralarasan Muthusamy Syncfusion Team June 24, 2020 05:42 AM UTC

Hi Stanislav, 
 
Thanks for contacting Syncfusion support. 
 
From your query, we understood that you need refresh the full Grid after adding a new column through the external action. In the below code, we have obtained the existing columns details and generated new columns structure using the details and re-rendered the Grid with new set of columns by using external button click. Please refer this code snippet and attached sample to achieve your requirement. 
 
@using Syncfusion.Blazor.Grids 
@using Syncfusion.Blazor.Buttons 
 
<SfButton Content="Add Columns" OnClick="AddCol"></SfButton> 
 
@if (ShowGrid) 
{ 
    <SfGrid @ref="Grid" Columns="Cols" DataSource="@OrderData"> 
   </SfGrid> 
} 
@code{ 
    public bool ShowGrid { get; set; } = true; 
    SfGrid<Order> Grid { get; set; } 
    public List<GridColumn> Cols = new List<GridColumn> { 
    new GridColumn(){ Field = "OrderID", Width = "100" }, 
    new GridColumn(){ Field = "CustomerID", Width = "100" }, 
    new GridColumn(){ Field = "EmployeeID", Width = "100" }, 
    }; 
    public async Task AddCol() 
    { 
        List<GridColumn> cols = await Grid.GetColumns(); // to get the exisitng columns 
        ShowGrid = false; // remove the Grid 
        StateHasChanged(); 
 
        Cols = new List<GridColumn>(); 
        foreach (var col in cols) // generate the existing column 
        { 
            Cols.Add(new GridColumn() { Field = col.Field, Width = "100" }); 
        } 
        Cols.Add(new GridColumn() { Field = "Freight", Width = "100", Format = "C2" }); // add new column here 
 
        ShowGrid = true; // re-render the Grid 
        StateHasChanged(); 
 
    } 
} 


Regards, 
Kuralarasan M 


Marked as answer
Loader.
Up arrow icon