AJF
AJF

Reputation: 1921

How to get pager back to first page on click event

I have an xpage with a dynamic view panel named dynamicViewPanel1 which changes depending on the radio button group selection between Views of Cancelled records and Not Cancelled records. The page includes a pager to advance to next pages etc. This all works fine. However, what I want is to have the pager return to the first page when the view is changed via the radio button. I have tried the code below as its all I can find so far on the internet. Basically if a user is on page 2 of the "Cancelled" view and then chnages to the "Not Cancelled" view by clicking on the radio button, it opens the "Not Cancelled" view on page 2 and does not return to page 1. But why won't this code below work?

I have also tried "gotoPage(0)" instead of "goToFirstPage(). I also tried changing getComponent("conflictPager") to getComponent("dynamicViewPanel1")

EDIT: I have included more of the page code for clarification. The btnRefresh is a hidden button activated on the radio group event to ensure the page refreshes.

<xp:panel>
  <xp:label value="This page provides options to view records that are  
   cancelled or NOT cancelled, i.e. Open or Completed"
   id="label5" style="font-weight:bold">
 </xp:label>
 <xp:br></xp:br>
 <xp:br></xp:br>
 <xp:radioGroup id="rgDuplicates" defaultValue="0">
   <xp:selectItem itemLabel="Not Cancelled" itemValue="0">
   </xp:selectItem>
   <xp:selectItem itemLabel="Cancelled" itemValue="1">
   </xp:selectItem>
   <xp:eventHandler event="onclick" submit="false">
     <xp:this.script><![CDATA[document.getElementById("#  
      {id:btnRefresh}").click()]]></xp:this.script>
   </xp:eventHandler>
   <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
     <xp:this.action><![CDATA[#{javascript:getComponent   
       ("dynamicViewPanel1").gotoFirstPage()}]]></xp:this.action>
   </xp:eventHandler></xp:radioGroup>
   <xp:button value="Refresh" id="btnRefresh"
     style="display:none">
     <xp:eventHandler event="onclick" submit="true"
       refreshMode="complete">
     </xp:eventHandler>
   </xp:button>
  <xp:panel id="maincontentpanel">
    <xe:dynamicViewPanel rows="30" id="dynamicViewPanel1"
      width="100%" partialRefresh="true" showCheckbox="true">
      <xe:this.data>
        <xp:dominoView var="view">
        <xp:this.viewName>
         <![CDATA[#{javascript:if(getComponent("rgDuplicates").getValue 
             () == "0"){
           viewName = "NotCancelled"
           } else {
           viewName = "Cancelled"
         }}]]>
       </xp:this.viewName>
     </xp:dominoView>
    </xe:this.data>
   </xe:dynamicViewPanel>
   <xp:br></xp:br>
   <xp:br></xp:br>
   <xp:button value="Delete" id="delete">
     <xp:eventHandler event="onclick" submit="true"   
       refreshMode="complete">
       <xp:this.action>
         <xp:actionGroup>
           <xp:confirm message="Are you sure?">
           </xp:confirm>
           <![CDATA[#{javascript:var viewPanel=getComponent
              ("dynamicViewPanel1");
               var docIDArray=viewPanel.getSelectedIds();
                for(i=0; i < docIDArray.length; i++){
                var docId=docIDArray[i];
                var doc=database.getDocumentByID(docId);
                doc.remove(true);
                }}]]>
           </xp:actionGroup>
         </xp:this.action>
       </xp:eventHandler>
     </xp:button>
   <xp:pager partialRefresh="true"
       layout="Previous Group Next" xp:key="footerPager"     
        id="conflictPager" for="dynamicViewPanel1">
 </xp:pager>
</xp:panel>
</xp:panel>

Upvotes: 1

Views: 591

Answers (1)

Thomas Adrian
Thomas Adrian

Reputation: 3636

I got it working using

getComponent("dynamicViewPanel1").gotoFirstPage()

Here is the complete code

<?xml version="1.0" encoding="UTF-8"?>
<xp:view xmlns:xp="http://www.ibm.com/xsp/core" xmlns:xe="http://www.ibm.com/xsp/coreex">
    <xp:radioGroup id="rgDuplicates" defaultValue="0">
        <xp:selectItem itemLabel="Not Cancelled" itemValue="0">
        </xp:selectItem>
        <xp:selectItem itemLabel="Cancelled" itemValue="1">
        </xp:selectItem>
        <xp:eventHandler event="onclick" submit="true" refreshMode="complete">
            <xp:this.action><![CDATA[#{javascript:getComponent("dynamicViewPanel1").gotoFirstPage();}]]></xp:this.action>
        </xp:eventHandler>
    </xp:radioGroup>
    <xe:dynamicViewPanel id="dynamicViewPanel1" rows="2">
        <xe:this.data>
            <xp:dominoView var="view1">
                <xp:this.viewName><![CDATA[#{javascript:var c = getComponent("rgDuplicates").getValue()
if(c=="1"){
    return "Start2"
}else{
    return "start"  
}
}]]></xp:this.viewName>
            </xp:dominoView>
        </xe:this.data>
    </xe:dynamicViewPanel>
    <xp:pager layout="Previous Group Next" partialRefresh="true" id="pager1" for="dynamicViewPanel1"></xp:pager>
</xp:view>

Upvotes: 1

Related Questions