Social Icons

twitterfacebookgoogle pluslinkedinrss feedemail


Thursday, October 21, 2010

Repeat Control – A better pagination (Version 8.5.1)

Here are few things you might need while working with Repeat Controls

How to get the repeat control object?

Var rptControl=getComponent("RepeatControlName")

How to get the total number of rows (all result pages combined) returned by the repeat control?


How to find if the repeat control returned any results?

rptControl.isRowAvailable() (Result is Boolean)

How to find the repeat limit or rows per page?


How to find the start value (think of the &start=1&count=30) of the current page of results?

rptControl. getFirst()

Now here is the code for displaying the pager control in a different way (I like the page numbers in a drop down)

No comments provided as the code is self explanatory

<xp:text escape="false" disableTheme="true">
                              <xp:this.value><![CDATA[#{javascript:var rptControl=getComponent("rptSrchResults");
var total=rptControl.getRowCount();
var from=(rptControl.getFirst() < total? (rptControl.getFirst() + 1 ) : total);
var tmpTo=rptControl.getFirst() + rptControl.getRows();
var to=(tmpTo < total? tmpTo : total);

"Your searched for <b>"+ getComponent("inpSrchUnits").getValue()+
"</b>: Displaying results <b>"+ from +"</b> to <b>"+ to + "</b> of a total of "+
"<b>"+total+"</b> results"

The actual pager control is hidden (display:none)

<xp:comboBox id="cmbPages">
                        <xp:this.value><![CDATA[#{javascript:var rptControl=getComponent("rptSrchResults");
if (rptControl==null) return [];
var total=rptControl.getRowCount();
var rowsperpage=rptControl.getRows();
var totalpages=Math.ceil(total/rowsperpage);
var arr=[];
for (var i=1;i<=totalpages;i++) {
return arr}]]></xp:this.value>
                  <xp:eventHandler event="onchange" submit="true"
var = getComponent("pager1");


  1. I like what you have done except that the pager doesn't work.

    The counter resets itself to the Repeat Limit + 1 and never resets itself so that there is no way to get back to page 1 if you have selected page 2 or greater.

    I would really like to use this if you can figure out why this is happening.

  2. Hi Roy,

    I had posted an update to this blog post. Can you try that and if that didn't work either, please let me know. I can then figure out what is missing.