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

Unable to use set_currentPageIndex on client side

9 Answers 76 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Nick Nowak
Top achievements
Rank 1
Nick Nowak asked on 13 Jan 2011, 12:09 AM
How can I set the current page index on client side.  I have used all of the below and none of them seem to change the index.

ClientEvents-OnDataBound

 

ClientEvents-OnDataBinding
ClientEvents-OnGridCreated
ClientEvents-OnGridCreating
ClientEvents-OnMasterTableViewCreated
ClientEvents-OnMasterTableViewCreating

 

 

 

Also, here is my code below:

function
rgSchoolMonitor_OnDataBinding()

 

{

 

var grid = $find("<%=rgSchoolMonitor.ClientID %>");

 

 

var masterTableView = grid.get_masterTableView();

 

 

 

var pageCount = masterTableView.get_pageCount();

 

 

if (pageCount > 1)

 

{

 

//Need to Iterate Through Pages

 

 

var pageIndex = masterTableView.get_currentPageIndex();

 

 

 

if ((pageIndex + 1) > (pageCount - 1))

 

{

masterTableView.set_currentPageIndex(0);

}

 

else

 

{

masterTableView.set_currentPageIndex((pageIndex + 1));

}

 

 

}

 

}


Thanks,
Nick

9 Answers, 1 is accepted

Sort by
0
Iana Tsolova
Telerik team
answered on 17 Jan 2011, 04:07 PM
Hello Nick,

Can you elaborate a bit more on your goal? When do you want to change the current page index? you can call the set_currentPageIndex() method outside the mention events, for instance on button click.

All the best,
Iana
the Telerik team
Browse the vast support resources we have to jump start your development with RadControls for ASP.NET AJAX. See how to integrate our AJAX controls seamlessly in SharePoint 2007/2010 visiting our common SharePoint portal.
0
Nick Nowak
Top achievements
Rank 1
answered on 17 Jan 2011, 05:34 PM
You can close this issue.  I was able to accomplish this server side.
0
Peter
Top achievements
Rank 1
answered on 29 Nov 2012, 03:06 AM
I get the error:

Object doesn't support this property or method

for:

$find("ctl00_MainContent_rgUnits").set_currentPageIndex(0);
0
Shinu
Top achievements
Rank 1
answered on 29 Nov 2012, 04:09 AM
Hi,

Try setting the PageIndex as shown below.
JS:
var masterTable = $find("<%= RadGrid2.ClientID %>").get_masterTableView();
masterTable.set_currentPageIndex(0);

Thanks,
Shinu.
0
Peter
Top achievements
Rank 1
answered on 30 Nov 2012, 12:00 AM
This doesn't seem to work with my command. 

If I am on Page 1 (Page 0) of the Grid, the command works fine. However if I'm on any other page this doesn't work - which suggests it's not setting the back back to Page 0. I tried a client-side rebind (after the Set Current Page Index) but it didn't work... 


<telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function AjaxReq(args) {
                $find("<%=rgUnits.ClientID %>").get_masterTableView().set_currentPageIndex(0);
                $find("<%= Master.FindControl("RadAjaxManager").ClientID %>").ajaxRequest("<%= txtUnitNumber.UniqueID %>", '');
            }
        </script>
    </telerik:RadCodeBlock>

...

<asp:TextBox runat="server" ID="txtUnitNumber" MaxLength="10" onkeyup="AjaxReq();" />


<asp:EntityDataSource ID="UnitEnityDataSource" runat="server" ConnectionString="name=FleetReplacementEntities"
                            DefaultContainerName="FleetReplacementEntities" EnableInsert="False" EnableUpdate="False" EnableDelete="False" EnableFlattening="False"
                            EntitySetName="Units" Where="it.SiteID = @SiteID AND (@UnitNumber IS NULL OR it.UnitNumber LIKE @UnitNumber + '%')" EntityTypeFilter="Unit" Include="BudgetCategory,EquipmentStatus,EquipmentType,EquipmentDescription,EquipmentCategory" OrderBy="it.BudgetCategory.BudgetCategory1">
                            <WhereParameters>
                                <asp:ControlParameter Name="SiteID" ControlID="ddlSites" PropertyName="SelectedValue" Type="Int32" />
                                <asp:ControlParameter Name="UnitNumber" ControlID="txtUnitNumber" PropertyName="Text" Type="String" />
                            </WhereParameters>
                        </asp:EntityDataSource>

0
Eyup
Telerik team
answered on 03 Dec 2012, 10:31 AM
Hi Peter,

Please try the following approach:
var masterTable = $find("<%= RadGrid1.ClientID %>").get_masterTableView();
masterTable.fireCommand("Page", 1); // page index
demonstrated in the following topic:
http://www.telerik.com/help/aspnet-ajax/grid-gridtableview-firecommand.html

I hope this will prove helpful. Please give it a try and let me know about the result.

Regards,
Eyup
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now.
0
Peter
Top achievements
Rank 1
answered on 05 Dec 2012, 05:25 AM
The command works to reset the Grid back to Page 1, but the EntityDataSource filter still doesn't work:

  • It needs a Set Timeout of roughly 500 milliseconds to work: setTimeout(RefreshGrid, 500);
  • The text-box loses focus when the grid refresh occurs

I know this isn't really a Telerik issue (more of a EntityDataSource control issue), but is there another way to have dynamic text filtering? 

First attempt:

<telerik:RadCodeBlock runat="server">
        <script type="text/javascript">
            function AjaxReq(args) {
                var masterTable = $find("<%= rgUnits.ClientID %>").get_masterTableView();
                masterTable.fireCommand("Page", 1);
                setTimeout(RefreshGrid, 500);
            }
             
            function RefreshGrid() {
                $find("<%= Master.FindControl("RadAjaxManager").ClientID %>").ajaxRequest("<%= txtUnitNumber.UniqueID %>", '');
            }
        </script>
    </telerik:RadCodeBlock>

Second  attempt (only reset when not page 1, and attempt to refocus):

function OnUnitNumberFilterFocus() {
                var masterTable = $find("<%= rgUnits.ClientID %>").get_masterTableView();
                if (masterTable.CurrentPageIndex != 0) {
                    masterTable.fireCommand("Page", 1);
                    $(#"<%=txtUnitNumber.ClientID %>").focus();
                }
            }

<asp:TextBox runat="server" ID="txtUnitNumber" MaxLength="10" Columns="10" onkeyup="AjaxReq();" onfocus="OnUnitNumberFilterFocus();" CssClass="unitNumber" />

Understandably, I get a stack-overflow with the focus method.

Third attempt (use select instead of focus):
function OnUnitNumberFilterFocus() {
                var masterTable = $find("<%= rgUnits.ClientID %>").get_masterTableView();
                if (masterTable.CurrentPageIndex != 0) {
                    setTimeout(SetPage1, 100);
                    setTimeout($("#<%=txtUnitNumber.ClientID %>").select(), 100);
                }
            }


The filtering box is basically cleared... the "SELECT" doesn't work. 

So now I might need an explicit checkbox or something that says "Filter Units" and this will toggle going back to page 1 and show/hide the filtering text-box (which really works fine when the grid is on page 1).
0
Peter
Top achievements
Rank 1
answered on 05 Dec 2012, 06:13 AM
There's also something very strange going on with the AjaxSettings... certain settings seem to make the filter text box lose focus, e.g.

<telerik:AjaxSetting AjaxControlID="RadAjaxManager">
                <UpdatedControls>
                    <telerik:AjaxUpdatedControl ControlID="txtUnitNumber" />  <%-- CAUSES PROBLEM --%>
                    <telerik:AjaxUpdatedControl ControlID="rgUnits" />
                    <telerik:AjaxUpdatedControl ControlID="ralp" />                   
                </UpdatedControls>
            </telerik:AjaxSetting>

... so I've removed this line and it seems to work better.
0
Eyup
Telerik team
answered on 07 Dec 2012, 09:07 AM
Hi Peter,

Could you please share what is your final goal? Please elaborate some more on your specific scenario and what exactly you are trying to achieve. Thus, we will be able to figure out your requirement and suggest a proper approach.

Greetings,
Eyup
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 RadControls for ASP.NET AJAX, subscribe to their blog feed now.
Tags
Grid
Asked by
Nick Nowak
Top achievements
Rank 1
Answers by
Iana Tsolova
Telerik team
Nick Nowak
Top achievements
Rank 1
Peter
Top achievements
Rank 1
Shinu
Top achievements
Rank 1
Eyup
Telerik team
Share this question
or