Blazor Refresh datagrid when adding new data

Hi can you help me with this problem, I want to refresh datagrid after i add new data how can you do that ? ill be glad if you can help me thank you

5 Replies 1 reply marked as answer

VN Vignesh Natarajan Syncfusion Team December 16, 2020 04:35 AM UTC

H Leonardo,  
 
Thanks for contacting Syncfusion support.  
 
Query: “I want to refresh datagrid after i add new data how can you do that ? 
 
We have analyzed your query and we suggest you to use Refresh() method of Grid to reflect the inserted record in Grid. We would like to inform that Grid will be refreshed automatically when record is inserted using default Editing feature. We suspect that you are inserting a record in external action or using Grid Events to save record into your database. So we suggest you to use Refresh() method or assign the updated data to Grid DataSource property.  
 
If you are still facing the issue, kindly get back to us with more details about the query.  
 
Regards, 
Vignesh Natarajan 



LE leonardo replied to Vignesh Natarajan December 17, 2020 05:22 AM UTC

H Leonardo,  
 
Thanks for contacting Syncfusion support.  
 
Query: “I want to refresh datagrid after i add new data how can you do that ? 
 
We have analyzed your query and we suggest you to use Refresh() method of Grid to reflect the inserted record in Grid. We would like to inform that Grid will be refreshed automatically when record is inserted using default Editing feature. We suspect that you are inserting a record in external action or using Grid Events to save record into your database. So we suggest you to use Refresh() method or assign the updated data to Grid DataSource property.  
 
If you are still facing the issue, kindly get back to us with more details about the query.  
 
Regards, 
Vignesh Natarajan 


Hi i appreciate your explanation, can you give me sample code? soorry but im still a newbie thank you so much


VN Vignesh Natarajan Syncfusion Team December 17, 2020 07:24 AM UTC

Hi Leonardo,  
 
Thanks for the update.  
 
Query: “i appreciate your explanation, can you give me sample code? 
 
From your query we suspect that you want to refresh the Grid manually after inserting a record on external action (without Grid default CRUD action). As per your request, we have prepared a sample to refresh the Grid externally. Refer the below code example.  
 
<SfButton OnClick="Record" Content="Add Record"></SfButton> 
<SfButton OnClick="Refresh" Content="Refresh"></SfButton> 
  
<SfGrid @ref="Grid" DataSource="@Orders" AllowPaging="true"> 
    <GridPageSettings PageSize="5"></GridPageSettings> 
    <GridColumns> 
        <GridColumn Field=@nameof(Order.OrderID) HeaderText="Order ID" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
        <GridColumn Field=@nameof(Order.CustomerID) HeaderText="Customer Name" Width="150"></GridColumn> 
        <GridColumn Field=@nameof(Order.OrderDate) HeaderText=" Order Date" Format="d" Type="ColumnType.Date" TextAlign="TextAlign.Right" Width="130"></GridColumn> 
        <GridColumn Field=@nameof(Order.Freight) HeaderText="Freight" Format="C2" TextAlign="TextAlign.Right" Width="120"></GridColumn> 
    </GridColumns> 
</SfGrid> 
  
@code{ 
    SfGrid<Order> Grid { getset; } 
    public static List<Order> Orders { getset; } = new List<Order>(); 
    public void Record() 
    { 
        Orders.Insert(0, new Order() { OrderID = Orders.Max(x => x.OrderID) + 1, CustomerID = "Added", Freight = 10, OrderDate = DateTime.Now }); 
    } 
    public void Refresh() 
    { 
        Grid.Refresh(); 
    } 
 
 
Kindly download the sample from below  
 
 
Please get back to us if you have further queries.  
 
Regards, 
Vignesh Natarajan 


Marked as answer

JO Jose April 3, 2024 10:00 PM UTC

Is it possible to do this action, and for the Grid's SfDataManager to kick off a Get request and get updated data?



PS Prathap Senthil Syncfusion Team April 4, 2024 11:07 AM UTC

Hi Jose,

Based on your requirements, we suggest utilizing the Grid's public method, AddRecordsAsync(), to achieve your desired outcome. Please refer to the following code snippet and sample for clarification.

    public async Task Add()

    {

        Order adddata = new Order()

            {

                OrderID = i ,

                CustomerID = "MJDGX",

                ShipCountry = "LONDON",

                Freight = 3.01

            };

        await this.Grid.AddRecordAsync(adddata);

        i++;

    }

 

  



Regards,
Prathap s


Loader.
Up arrow icon