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