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

[Solved] Which combination of client events would I use to persist and restore what page the grid should be on after rebind() in an ajax client-binding scenario?

3 Answers 49 Views
Grid
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Rob
Top achievements
Rank 1
Rob asked on 13 Dec 2011, 11:21 PM
Hi there,

What combination of grid client events can I use to persist the current page the grid is focused on and then jump to that page after a full page refresh?

I know I can get the grid.currentPage in the OnDataBound() event.  And I can see the change from my persisting this value in a page-scoped variable versus what is in in e.Page in the OnDataBinding(e) event.  But I am uncertain at which point I should do grid.pageTo(_currentPage) in order to restore the previously selected page after a grid.rebind(). 

The documentation here suggests that after the ajax call completes, I can listen to OnComplete() and I thought that might be a time to set the page to jump to since it is after the data is retrieved and prior to the grids binding process, but there is no such event on the MVC Telerik Grid... so I am a little confused, but perhaps that's the wrong way to go to begin with.

Any help is appreciated!

Thanks,

Rob

3 Answers, 1 is accepted

Sort by
0
Daniel
Telerik team
answered on 16 Dec 2011, 03:24 PM
Hello Rob,

The OnComplete event was introduced in the latest(Q3 2011) release so if you have an older version it won't be available.
In my opinion the OnLoad event should be suitable for your scenario, since you need to navigate back to the previously selected page only once after the page is reloaded.
However, after a full page reload the variable that hold the last requested page will not be persisted. To preserve the Grid's page you could store it in the Session or the TempData in the Grid's Select action and then set it in the Pagable configuration. For example:

//Controller
public ActionResult Index()
        {
            if (Session["page"] == null)
            {
                Session["page"] = 1;
            }
            return View(order);
        }
 
[GridAction]
public ActionResult _Select(GridCommand command)
{
    Session["page"] = command.Page;
    return View(new GridModel(GetData()));
}
 
//View
 
.Pageable(settings => settings.PageTo((int)Session["page"]))


All the best,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
0
Rob
Top achievements
Rank 1
answered on 16 Dec 2011, 06:00 PM
Hi Daniel,

Thanks for the reply!

Ahh, so we need to update to a new version for OnComplete.

I can see how what you suggested would work for persisting the page after full page reloads, but what I am trying to do is persist what user the page was on after a grid.rebind() is called on the client side in javascript.  Is there a way to set which page should be selected on the client as part of the rebind() process, but not cause the grid to retrieve data twice -- once for page 1 after the initial grid.rebind() and then again after a call to grid.pageTo()?  OnLoad() fires only after a full page reload, but since I am using custom ajax binding, I need to insert this somewhere as part of the rebind process.

Thanks!

Rob
0
Daniel
Telerik team
answered on 19 Dec 2011, 03:34 PM
Hello Rob,

You could use the Grid's client-side ajaxRequest method.  It works the same way as rebind except that ajaxRequest preserves the Grid's state(current page, sorting order and filters). Otherwise a second call will be necessary to return to the same page.

Best wishes,
Daniel
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the Telerik Extensions for ASP.MET MVC, subscribe to their blog feed now
Tags
Grid
Asked by
Rob
Top achievements
Rank 1
Answers by
Daniel
Telerik team
Rob
Top achievements
Rank 1
Share this question
or