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

prevent-losing-batch-editing-changes-on-paging-or-any-other-postback

7 Answers 161 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Lenny_shp
Top achievements
Rank 2
Lenny_shp asked on 11 Sep 2014, 05:00 PM
http://www.telerik.com/support/code-library/prevent-losing-batch-editing-changes-on-paging-or-any-other-postback

Where do I set to ignore the [Save changes] button that will be doing the update?    I get the same prompt that changes will be lost.

7 Answers, 1 is accepted

Sort by
0
Lenny_shp
Top achievements
Rank 2
answered on 11 Sep 2014, 08:12 PM
How do I skip [Save changes] button from batch Edit to trigger cancel prompt?

    // Prevents other RadGrid commands
    functionLibrary.gridCommand = function (sender, args) {
        if (changesString.length > 0 && !confirmationHandled) {
            confirmationHandled = confirm(message);
            args.set_cancel(!confirmationHandled);
        }
    }
0
Eyup
Telerik team
answered on 16 Sep 2014, 10:56 AM
Hello Lenny,

The latest release version of the controls introduced a new OnUserAction client-side event handler which makes this requirement a much more straightforward task. You can subscribe to this handler and cancel it depending on some specific conditions:
http://demos.telerik.com/aspnet-ajax/grid/examples/data-binding/client-side/client-data-source-binding/defaultcs.aspx?product=clientdatasource

Hope this helps.


Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lenny_shp
Top achievements
Rank 2
answered on 16 Sep 2014, 01:30 PM
Thanks, the sample code for OnUserAction doesn't prompt for these actions that would lose the changes:

1. Closing browser
2. Clicking on Refresh button

How can I add those two actions to the prompt?
0
Lenny_shp
Top achievements
Rank 2
answered on 17 Sep 2014, 09:20 PM
I switched from OnUserAction to OnCommand to capture the [Refresh] button and custom filter.
I guess there is no easy way to incorporate the browser exit warning via this method.

<ClientEvents OnCommand="CheckChanges" />

            function CheckChanges(sender, args) {
                if (sender.get_batchEditingManager().hasChanges(sender.get_masterTableView()) && (args.get_commandName() != "BatchEdit") &&
                    !confirm("Unsaved changes will be lost.  Proceed?")) {
                    args.set_cancel(true);
                }
            }
0
Eyup
Telerik team
answered on 19 Sep 2014, 01:12 PM
Hi Lenny,

You can check the sample mentioned in your first post to implement browser preventing:
// Prevents closing the browser or navigating from the page
window.onbeforeunload = function () {
    if (!confirmationHandled && changesString.length > 0) {
        return message;
    }
    else {
        confirmationHandled = false;
    }
}

Here you can remove the confirmationHandled condition and get changesString from some global variable which holds the Batch changes.

That should do the trick.

Regards,
Eyup
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
0
Lenny_shp
Top achievements
Rank 2
answered on 22 Sep 2014, 02:46 PM
How do I suppress BatchEdit button from kicking off onbeforeunload?   onRequestStart fires first then onbeforeunload.

(args.get_commandName() != "BatchEdit")

window.onbeforeunload = function () {
                var grid = $find("<%=RadGrid1.ClientID %>");
                if (grid.get_batchEditingManager().hasChanges(grid.get_masterTableView())) {
                    return "Unsaved changes will be lost.  Proceed?";
                }
}
0
Viktor Tachev
Telerik team
answered on 25 Sep 2014, 09:31 AM
Hi Lenny,

For your convenience I have prepared a sample project where the functionality is implemented. Give it a try and let me know how it works for you.

Regards,
Viktor Tachev
Telerik
 

Check out the Telerik Platform - the only platform that combines a rich set of UI tools with powerful cloud services to develop web, hybrid and native mobile apps.

 
Tags
Grid
Asked by
Lenny_shp
Top achievements
Rank 2
Answers by
Lenny_shp
Top achievements
Rank 2
Eyup
Telerik team
Viktor Tachev
Telerik team
Share this question
or