We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Multiple rows creation in grid

Hi,

Is there any option to create multiple rows at once in a grid in batch edit mode? I mean, if I need to create 20 rows, should I call to Grid.AddRecordAsync() 20 times?

Thanks!

David


3 Replies

PS Prathap Senthil Syncfusion Team March 1, 2023 08:19 AM UTC

Hi David,

Query:” Is there any option to create multiple rows at once in a grid in batch edit mode? I mean, if I need to create 20 rows, should I call to Grid.AddRecordAsync()”

yes, you can use the AddRecordAsync method to create multiple rows at once in batch edit mode. However, to ensure that the added data is stored on the datasource using batch editing, you need to call the EndEditAsync() method. We have created a simple sample that you can refer to. Please find the attached code snippet and sample for your reference.



<SfButton @onclick="AddRecord">AddData</SfButton>

 

<SfGrid @ref="Grid" TValue="Order" DataSource="@Orders">

    <GridEditSettings AllowAdding="true" AllowEditing="true" AllowDeleting="true" ShowConfirmDialog="false" Mode="EditMode.Batch" ></GridEditSettings>

</SfGrid>
    public async Task AddRecord()

    {

 

        await Grid.AddRecordAsync(new Order() { OrderID = orderId, CustomerID = "New", Freight = 223.2, OrderDate = DateTime.Now });

        orderId++;

        await Grid.EndEditAsync();

      

 

    }


Reference:
https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_AddRecordAsync
                     https://help.syncfusion.com/cr/blazor/Syncfusion.Blazor.Grids.SfGrid-1.html#Syncfusion_Blazor_Grids_SfGrid_1_EndEditAsync


Regards,
Prathap S


Attachment: BlazorDataGrid_bcbf2e59.zip


DG David González Martínez March 1, 2023 08:44 AM UTC

Thanks! However, the example is not exactly what I'm looking for. I ask for multiple rows creation in a single button click. In that case, should I create a loop and call to AddRecordAsync() n times or is there some method that accepts a list of rows to add to the grid?



PS Prathap Senthil Syncfusion Team March 5, 2023 02:02 PM UTC

Thanks for the update,

Query: "Is there some method that accepts a list of rows to add to the grid?"

We regret to inform you that currently, we don’t have a list of the data added to the grid instance method. Instead, we suggest using a loop to add the data using AddRecordasync() method. Please get back to us if you have any further queries.


Loader.
Live Chat Icon For mobile
Up arrow icon