New to Telerik UI for ASP.NET AJAX? Download free 30-day trial

RadGrid ClientDataSource binding and batch editing: page is reset to 1 after deleting a record

Problem

Client side bound Radgrid with batch editing: if you page the grid and do a client side delete. then save the changes, the active page in the pager goes to number 1 page.

Solution

You can store the current page index when a row is deleted and in the next page command, .page() the grid to the previous page.

<script>
        var currPageWhenDeleting;

        function OnRowDeleted(sender, args) {
            currPageWhenDeleting = sender.get_masterTableView().get_currentPageIndex();
        }

        function OnCommand(sender, args) {
            if (currPageWhenDeleting && args.get_commandName() == "Page") {
                args.set_cancel(true);
                var restorePage = currPageWhenDeleting;
                currPageWhenDeleting = null; //clear the original flag to avoid an endless loop
                setTimeout(function () {
                    sender.get_masterTableView().page(restorePage + 1); //restore the previous page
                }, 100);
            }
        }
</script>
<telerik:RadGrid RenderMode="Lightweight" ID="RadGrid1" runat="server">
   <MasterTableView EditMode="Batch">
    <ClientSettings>
        <ClientEvents OnCommand="OnCommand" OnRowDeleted="OnRowDeleted" />
    </ClientSettings>
</telerik:RadGrid>

See Also

In this article
Not finding the help you need? Improve this article