Warning message "Unsaved changes will be lost. Are you sure you want to continue?" on a successful save of newly added records

Hi There,

On save of newly added records, the user receives the warning message "Unsaved changes will be lost. Are you sure you want to continue?". For other edits (modify, delete), this does not occur. Any idea why?


Below is my OnBatchSave event handler:



    public async Task ProductsDataGridOnBatchSaveHandler(BeforeBatchSaveArgs<ProductViewModel> args)

    {

        var batchChanges = args.BatchChanges;

        if (batchChanges.AddedRecords.Count > 0)

        {

            // Add new Products to the database

            foreach (var record in batchChanges.AddedRecords)

            {

                record.BeforeSaving();


                if (await ApiHelper.ExecuteCallGuardedAsync(

                    () => ProductsClient.CreateMyAsync(record.Adapt<CreateMyProductRequest>()), Snackbar, _customValidation) is Guid guid)

                {

                    if (!guid.Equals(Guid.Empty))

                    {

                        record.Id = guid;

                        Snackbar.Add(L["Your Product '{0}' has been added.", record.Name], MudBlazor.Severity.Success);

                    }

                    else

                    {

                        Snackbar.Add(L["Your Product '{0}' could not be added. Please try again.", record.Name], MudBlazor.Severity.Error);

                    }

                }

            }

        }


        if (batchChanges.ChangedRecords.Count > 0)

        {

            // Send updates to Products to the database

            foreach (var record in batchChanges.ChangedRecords)

            {

                record.BeforeSaving();


                if (await ApiHelper.ExecuteCallGuardedAsync(

                  () => ProductsClient.UpdateMyAsync(record.Id, record.Adapt<UpdateMyProductRequest>()), Snackbar, _customValidation) is Guid guid)

                {

                    if (!guid.Equals(Guid.Empty))

                    {

                        Snackbar.Add(L["Your Product '{0}' has been updated.", record.Name], MudBlazor.Severity.Success);

                    }

                    else

                    {

                        Snackbar.Add(L["Your Product '{0}' could not be updated. Please try again.", record.Name], MudBlazor.Severity.Error);

                    }

                }

            }

        }


        if (batchChanges.DeletedRecords.Count > 0)

        {

            // Datagrid has delete confirmation (using setting ShowDeleteConfirmDialog="true")

            // Delete the Product

            foreach (var record in batchChanges.DeletedRecords)

            {

                if (await ApiHelper.ExecuteCallGuardedAsync(

                        () => ProductsClient.DeleteMyAsync(record.Id), Snackbar, _customValidation) is Guid guid)

                {

                    if (!guid.Equals(Guid.Empty))

                    {

                        Snackbar.Add(L["Your Product '{0}' has been deleted.", record.Name], MudBlazor.Severity.Success);

                    }

                    else

                    {

                        Snackbar.Add(L["Your Product '{0}' could not be deleted. Please try again.", record.Name], MudBlazor.Severity.Error);

                    }

                }

            }

        }

    }



G


4 Replies

SP Sarveswaran Palani Syncfusion Team September 14, 2022 08:21 PM UTC

Hi Gerald,


Greetings from Syncfusion support.


We have analyzed your query and suggest you to enable ShowConfirmDialog Property as true in GridEditSettings component to overcome the issue. We have already discussed this topic in our UG documentation. Kindly refer the attached documentation link for your reference.


Reference: https://blazor.syncfusion.com/documentation/datagrid/batch-editing#confirmation-dialog


If you have any further queries, kindly share the runnable entire sample to us, It’ll be more helpful for us to further validate the query and provide the solution as early as possible.


Regards,

Sarveswaran PK




MW Mark Wint March 19, 2023 06:24 PM UTC

Hi,


This still seem to be an issue with the latest release. Here is my Grid, Every time I add a new item, I get a confirm dialog to add the item, but then immediately get a dialog about unsaved changes. the new item DOES get added to the database, so I don't understand why this appears.


<SfGrid TValue="@IEC104Mappings" DataSource="@mappings" Height="400" AllowPaging="true" AllowFiltering="true" AllowExcelExport="true" Toolbar="@(new List<string>() { "Add","Edit", "Delete", "Cancel", "Update","ExcelExport" })">

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

    <GridEvents OnBatchSave="OnBatchSaveHandler" OnBatchDelete="BatchDeleteHandler" TValue="IEC104Mappings"></GridEvents>

    <GridFilterSettings Type ="Syncfusion.Blazor.Grids.FilterType.Menu"></GridFilterSettings>

<GridColumns>

<GridColumn Field=@nameof(IEC104Mappings.Name) HeaderText="Name" Width="150"></GridColumn>

<GridColumn Field=@nameof(IEC104Mappings.ObjectAddress) Type="ColumnType.Number" HeaderText="Address" Width="100"></GridColumn>

<GridColumn Field=@nameof(IEC104Mappings.ModifiedOn) HeaderText="Modified On" Width="100"></GridColumn>

<GridColumn Field=@nameof(IEC104Mappings.CreatedOn) HeaderText="Created On" Width="100"></GridColumn>

</GridColumns>

</SfGrid>



DK Daniel Koffler March 19, 2023 07:52 PM UTC

Same problem here.



VN Vignesh Natarajan Syncfusion Team March 20, 2023 07:27 AM UTC

Hi Mark/Daniel,


Thanks for contacting Syncfusion support.


Query: ” This still seem to be an issue with the latest release. Here is my Grid, Every time I add a new item, I get a confirm dialog to add the item, but then immediately get a dialog about unsaved changes


We have prepared a sample using your code example, but we are unable to reproduce the reported issue at our end. Refer to the below-attached sample for your reference. Also, you have not enabled the IsPrimaryKey property in the grid. It is necessary to perform CRUD operation properly in Grid. So kindly enable the IsPrimaryKey property to any one of the available columns whose value is unique.


https://blazor.syncfusion.com/documentation/datagrid/editing

https://blazor.syncfusion.com/documentation/datagrid/batch-editing


If the reported issue still persists, kindly share the details about the event handlers of GridEvents which might have caused the reported issue. It will be very helpful in validating the reported issue further at our end and providing a solution as early as possible


Regards,

Vignesh Natarajan


Attachment: BlazorApp1_e3d7bea0.zip

Loader.
Up arrow icon