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

Prevent paging number from changing client side on confirm

1 Answer 122 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Eric
Top achievements
Rank 1
Eric asked on 21 Apr 2014, 04:19 PM
Is it possible to prevent the paging number from changing or to revert back to the previous page number client side?

Right now if the user has made changes to the grid I am able to prevent a postback during the OnCommand client side event but the the page number has already changed which is confusing for the users as they are not able to reselect the page number after they have saved their changes and are ready to move on.

1 Answer, 1 is accepted

Sort by
0
Shinu
Top achievements
Rank 2
answered on 22 Apr 2014, 05:10 AM
Hi Eric,

By default, RadGrid does not provide cancellation of paging on the client without posting back to the server. Even if you hook up to the OnCommand client-side event and set set_cancel(true), RadGrid will still postback, without changing the page. If this is OK with you, you can simply use:

JS:
function onCommand(sender, args)
{
  if(args.get_commandName() == "Page")
  {
    args.set_cancel(confirm("Are you sure you want to page?"));
  }
}

This, however, will not prevent postback to the server. If you need to prevent any postback at all, the easiest approach to take is to find all your anchor and input elements in the pager row and assign additional click event handlers to them:

JS:
function gridCreated(sender, args) {
    var pagerRow = sender.get_masterTableView().get_element().tFoot;
    var anchors = pagerRow.getElementsByTagName('a');
    for (var i = 0; i < anchors.length; i++) {
        if (anchors[i].className != "rgCurrentPage" && anchors[i].href.indexOf("javascript:__doPostBack") > -1) {
            var clickScript = anchors[i].attributes["onclick"].value;
            anchors[i].onclick = confirmPage;
        }
    }
  
    var submits = pagerRow.getElementsByTagName('input');
    for (var i = 0; i < submits.length; i++) {
        if (submits[i].type == "submit") {
            submits[i].onclick = confirmPage;
        }
    }
}
  
function confirmPage()
{
    return confirm("Are you sure to Page?");
}

The above code seems quite more complicated from the previous, but it assigns a confirmPage() handler to each and every button in the pager, so that you can cancel paging without raising any further events.

Thanks,
Shinu
Tags
Grid
Asked by
Eric
Top achievements
Rank 1
Answers by
Shinu
Top achievements
Rank 2
Share this question
or