Batch Editing - I'd like to stop the user from paging when the grid is Dirty

I know I can use ShowConfirmDialog and the user will be prompted which is great, but I don't want the user to be prompted if they clicked the Save or Cancel toolbar buttons.  Is it possible to only have ShowConfirmDialog fire when the user tries to change pages?

Or is there another event that I can hook into to warn the user that their changes would be lost?

Or is there a way to call the batch "save" method automatically on when a paging event occurs?


1 Reply

SP Sarveswaran Palani Syncfusion Team February 23, 2024 02:34 AM UTC

Hi Seth,

Greetings from Syncfusion support.


From your query, it seems that you are looking to display a confirmation dialog when changing pages, particularly when values are not in a saved state. To address this requirement, we have created a sample utilizing the IsDirtyAsync method and a custom SfDialog component within the page-changing event. This setup triggers a confirmation dialog when attempting to change pages while unsaved values are present, serving as a reminder for users to save their changes. You can find the attached sample along with the corresponding code snippet for your reference.


Sample: https://blazorplayground.syncfusion.com/embed/LtrJjVhLUawMrBbn?appbar=true&editor=true&result=true&errorlist=true&theme=bootstrap5

<SfDialog @ref="Dialog" Width="250px" Visible="false" ShowCloseIcon="true" IsModal="true">

    <DialogTemplates>

        <Content> Unsaved Changes Will be Saved!!! </Content>

    </DialogTemplates>

    <DialogButtons>

        <DialogButton OnClick="@OkClick" Content="OK" IsPrimary="true"></DialogButton>

        <DialogButton OnClick="@CancelClick" Content="Cancel"></DialogButton>

    </DialogButtons>

</SfDialog>

 

<SfGrid @ref="Grids" DataSource="@Orders" AllowPaging="true" Toolbar="@(new List<string>() { "Add", "Delete", "Update", "Cancel" })" Height="315">

    <GridEvents PageChanging="PageChangingHandler" TValue="Order"></GridEvents>

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

    <GridColumns>

    .

    .

    </GridColumns>

</SfGrid>

 

@code {

    int pagenumber;

 

    private void OkClick()

    {

        Grids.EndEditAsync();

        Dialog.HideAsync();

        Grids.GoToPageAsync(pagenumber);

    }

 

    private void CancelClick()

    {

        Dialog.HideAsync();

    }

 

    public async Task PageChangingHandler(GridPageChangingEventArgs args)

    {

        bool isDirty = await Grids.IsDirtyAsync();

        if (isDirty)

        {

            args.Cancel = true;

            pagenumber = args.CurrentPage;

            Dialog.ShowAsync();

        }

    }

}


If you have any further questions or need additional assistance, please feel free to reach out.

Regards,
Sarvesh


Loader.
Up arrow icon