I have a rad grid that I create on server-side.
I use paging with virtual item count, and I load data on demand (every time the page index changes, I load the relevant rows, so my grid contains every time number of rows = page size).
I added 2 buttons, prev and next, that iterates over my grid rows.
It works fine on the first page, but when I want to change the page and select the first item, the page index doesn't change.
Here is my code:
MasterTable.clearSelectedItems();
MasterTable.set_currentPageIndex(NextPageIndex,
true);
MasterTable.rebind();
MasterTable.selectItem(0);
set_currentPageIndex, doesn't make the function
GridReport_PageIndexChanged
to be fired.
The rebind calls need data source and there I check the pageIndex, and I get the index before the change..
Do you have any idea what am I doing wrong?
How can I change the page index using java script?
Thanks.
7 Answers, 1 is accepted
This approach is applicable only in the case of server-side binding. Then you will not need to call the rebind() method on the client because it is specific only for client-side binding.
In order to fire the PageIndexChanged event on the server you have to call the the set_currentPageIndex method with second parameter false:
masterTableView.set_currentPageIndex(1,
false
)
Marin
the Telerik team

Thanks for your reply.I tried to call:
masterTableView.set_currentPageIndex(1,
false
)
but still PageIndexChanged event on the server didn't fire.
When I call rebind() on client side after set_currentpage, inside needDataSource on server I get the old value in the CurrentPageIndex property...
Another option that you can try is to call the fireCommand method on the client. This way the grid will postback and you should see the new page index in the CurrentPageIndex property. The PageIndexChanged event will also fire approapriately. Here is a sample code:
var
masterTable = $find(
'<%= RadGrid1.ClientID %>'
).get_masterTableView();
masterTable.fireCommand(
"Page"
,
"4"
);
//no need to call rebind() on the client
Marin
the Telerik team

Thanks for the reply.
I tried this code, and PageIndexChanged is called, but e.NewPageIndex still holds the old value.
I called:
var
masterTable = $find(
'<%= GridReport.ClientID %>'
).get_masterTableView();
masterTable .fireCommand("Page", NextPageIndex);
var NextPageIndex = 0;
and I get:
public void GridReport_PageIndexChanged(object source, GridPageChangedEventArgs e)
{
//HERE e.NewPageIndex = 0!!
Session["CurrentPageIndex"] = e.NewPageIndex;
}
Do you have any idea why?
Thanks.
In case you are using custom paging for the grid make sure the following requirements are fulfilled then the page index should be available in the NeedDataSource event.
More information on how to perform custom paging can also be found in this demo.
Marin
the Telerik team

I checked, and all the requirements are fulfilled, but I get wrong value inside PageIndexChanged event.
What should I do?
Can you give me any code example or refference?
I just want to add simple functionaliity..
Thanks.
You can handle the ItemCommand on the server where the new page index should be accessible in the command arguments. See attached page for further reference.
Regards,Marin
the Telerik team