0
votes

I am using the Telerik MVC grid, with Ajax data binding.

I would like to do 2 things with the Telerik MVC Grid:

  1. When a row is selected, detect (client side) which page the grid is currently on as well as which row was selected.
  2. The next time the grid is loaded (using ajax ... I never leave the page), page back to the same page to show the last select. (I guess I am really just asking if there is a way to immediately go to a page of the grid once the data is loaded, rather than page 1)

Please keep in mind, I am aware of the client side events already. I would like to know how to do #1 from the event, and #2 either from the client side or programatically somehow.

Edit/More Details: I think I know what I need to do here. Since I am using Ajax loading here, the Ajax POST is being called somewhere in the Telerik code. I can see that during that Ajax POST they are sending a "page" parameter to the controller. If I could edit that somehow, I am sure it would work - but I am having trouble changing that parameter.

Thanks in advance!

1

1 Answers

0
votes

For the sake of anyone else looking for this, I figured it out:

Getting the current page of the Grid: To do this, I use jQuery to determine which number has the "selected" style (t-state-active) to determine the current page number. Example (my grid id is 'cases-grid'):

function getCurrentGridPage() {
        ///<summary>Gets the current page of the #cases-grid</summary>
        var page = $('#cases-grid .t-state-active');
        if (page.length == 0) {
            return 1; //default to page 1 when unknown
        }
        return page.text();
    }

The second part of my question was actually well documented on the Telerik site ... I just missed it for awhile. To load the grid to a specific page (other than 1) I added the following to my grid:

.Pageable(pager => pager.PageTo(@Model.InitialPage))

And added the InitialPage property to my model.