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.
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.
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.