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

set_currentPageIndex difficulties

2 Answers 117 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Blake
Top achievements
Rank 1
Blake asked on 24 Feb 2012, 02:52 PM
Hello,

I am currently using radgrid client-side databinding, very similar to the example here: http://demos.telerik.com/aspnet-ajax/grid/examples/client/databinding/defaultcs.aspx

What I want to do is have the user page, sort, filter, select rows, etc and have the server-side code capturing those values in session.  If for any reason the page is refreshed, I want to initialize the grid back to those session values (sort/filter/page/selected row).

I can get almost all of this working with the exception of the page index.  It appears to work, but then the grid immediately fires a page change back to page 0.

Any insight into why this is happening?



2 Answers, 1 is accepted

Sort by
0
Blake
Top achievements
Rank 1
answered on 24 Feb 2012, 04:19 PM
Scouring the forums I found the following post:

> It looks like it says "0 to 0 of Y". Once you change to a different page it corrects itself. Very odd.

Ah yes it's coming back to me. In order to fix the aforementioned "0 to 0 of y" I remember having to do:

view.set_virtualItemCount(count);
view.CurrentPageIndex = -1;
view.set_currentPageIndex(pageIndex, true);

The problem with the "Page" command firing arose because in the code-behind Page_Load() I was telling the grid what the CurrentPageIndex was (which was grabbed from a cookie). That, combined with the internal call to set_currentPageIndex(0) that line 1 above does, caused ANOTHER client-side "Page" command to fire and fetch the data twice.

I ended up having to add "view.CurrentPageIndex = 0;" before calling set_virtualItemCount() in order for the internal call to set_currentPageIndex(0) to be ignored and not fire the "Page" command. The third line passes the undocumented second parameter "true" to set_currentPageIndex(), to avoid firing the command but to render the page numbers correctly. And it took me about a day to figure out those two hacks.

-----------------------

Based on this information, I used the following code and the erroroneous 2nd page change doesn't fire:

var

 

 

tableView = grid.get_masterTableView();

 

 

tableView.set_dataSource(result.Items);

tableView.dataBind();

 

 

 

var currentPageIndex = tableView.get_currentPageIndex();

 

tableView.CurrentPageIndex = 0;

tableView.set_virtualItemCount(result.TotalItemCount);

tableView.set_currentPageIndex(currentPageIndex,

 

true);

 

0
Yew
Top achievements
Rank 1
answered on 31 Jul 2013, 02:54 AM
Thank you Black... You saved my day....
Tags
Grid
Asked by
Blake
Top achievements
Rank 1
Answers by
Blake
Top achievements
Rank 1
Yew
Top achievements
Rank 1
Share this question
or