New to Telerik UI for ASP.NET Core? Start a free 30-day trial
Show Confirmation Popup When User Leaves the Page with Unsaved Grid Changes
Updated over 6 months ago
Environment
| Product | Telerik UI for ASP.NET Core Grid |
| Progress Telerik UI for ASP.NET Core version | 2024.4.1112 |
Description
How can I detect changes in an InLine editable Grid when the user tries to leave the page and prompt the user with a warning message about the unsaved changes?
Solution
To detect the changes in the Grid when the user attempts to navigate away from the page with the Grid, you can check whether there has been a change in the Grid's DataSource. If at least one change occurs, show the prompt.
- Handle the
beforeunloadevent of the current window. - Get a reference to the Grid and access its DataSource.
- Check the
dirtyflag of the data items, which indicates that the data item has been changed. - Show the popup if at least one change occurs.
Razor
@(Html.Kendo().Grid<ProductViewModel>()
.Name("grid")
.Editable(editable => editable.Mode(GridEditMode.InLine))
...// Additional configuration.
)