Prompt to save changes when in batch editing mode

3 posts, 0 answers
  1. Martin
    Martin avatar
    7 posts
    Member since:
    Nov 2006

    Posted 29 Jul 2013 Link to this post


    I'm using the grid in an MVC 4 application, utilising the batch editing. I have two problems with the grid that I cannot work out.

    1) If the user tries to navigate away from the page while there are dirty models I wish to prompt them appropriately. I tried the script below, however the data collection is of zero length and hasChanges returns false. Could you advise on the best way of providing this functionality please.
    window.onbeforeunload = confirmLeavePage();
    function confirmLeavePage() {
        var dataSource = $("#ValuesGrid").data("kendoGrid").dataSource;
        var data =;
        var hasChanges = dataSource.hasChanges();
        for (var loop = 0; loop < data.length; loop++) {
            if (data[loop].dirty) {
                hasChanges = true;
        if (hasChanges) {
            return "You have made changes to the current values. The changes will be lost if you leave this page without clicking the save button";

    2) If the grid is paged and you make changes in page 1 you correctly get the red indicator to show the changes, however if you navigate to page 2 and then back to page 1 the red indicator is no longer visible.
  2. Martin
    Martin avatar
    7 posts
    Member since:
    Nov 2006

    Posted 30 Jul 2013 Link to this post

    Managed to get this working. I don't really see the differences between what I posted and this but it seems to work.
  3. Kendo UI is VS 2017 Ready
  4. Kiril Nikolov
    Kiril Nikolov avatar
    2566 posts

    Posted 30 Jul 2013 Link to this post

    Hi Martin,

    I am glad that you fixed the prompt message for saving changes.

    Regarding you second question about preserving the "dirty flag" on the grid with batch editing, I would suggest you to take a look at this Code Library showing a possible implementation of this functionality:
    Kiril Nikolov
    Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Back to Top