This is a migrated thread and some comments may be shown as answers.

Prompt to save changes when in batch editing mode

2 Answers 404 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Saj
Top achievements
Rank 1
Saj asked on 29 Jul 2013, 01:48 PM
Hi,

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() {
    debugger;
    var dataSource = $("#ValuesGrid").data("kendoGrid").dataSource;
    var data = dataSource.data();
 
    var hasChanges = dataSource.hasChanges();
 
    for (var loop = 0; loop < data.length; loop++) {
        if (data[loop].dirty) {
            hasChanges = true;
            break;
        }
    }
 
    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 Answers, 1 is accepted

Sort by
0
Saj
Top achievements
Rank 1
answered on 30 Jul 2013, 01:10 PM
Managed to get this working. I don't really see the differences between what I posted and this http://jsfiddle.net/fZjha/21/ but it seems to work.
0
Kiril Nikolov
Telerik team
answered on 30 Jul 2013, 02:00 PM
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:

http://www.kendoui.com/code-library/web/grid/preserve-the-dirty-indicator-in-incell-editing-and-client-operations.aspx
 
Regards,
Kiril Nikolov
Telerik
Join us on our journey to create the world's most complete HTML 5 UI Framework - download Kendo UI now!
Tags
Grid
Asked by
Saj
Top achievements
Rank 1
Answers by
Saj
Top achievements
Rank 1
Kiril Nikolov
Telerik team
Share this question
or