A simpler pagination view for Lotus Notes documents on the Web
Frustrated by clicking through endless "Next" buttons to reach a buried Lotus Notes document? Learn how to create a simpler pagination view for Lotus Notes documents on the Web
Do you get frustrated by having to click through endless "Previous" or "Next" buttons to find a buried Lotus Notes document that is, for example, on the tenth page.
Since a Web browser may take a long time, Notes/Domino developers like to keep to a minimum of 50 documents per page and provide the normal Previous/Next buttons, using the Lotus Domino @DbCommand("Domino"; "ViewPreviousPage") and @DbCommand("Domino"; "ViewNextPage").
Below you'll find code and instructions that will allow you to insert a computed value in your $$ViewtemplateDefault template. Once implemented, your Lotus Notes users will find it much easier to navigate through multiple pages on the Web.
Along with this, you will have the Previous/Next button, First/Last, GoTo page, and Documents per page features.
Step 1: Create three "computed for display" fields on your $$ViewtemplateDefault template, and label them as follows:
ViewName :@Subset(@ViewTitle;-1) ParamCount :@UrlQueryString("count") ParamStart :@UrlQueryString("start")
Step 2: Copy the following code into the form:
<table border=0 width=50% align=center> <tr><td colspan=2 align=center class= viewheader><b> Configuration</b></td></tr> <tr> <td><b>Documents Per Page :</b></td> <td> <select name='Pages' onChange='DocsPerPage()'> <option> --Select--</option> < option value='5'>5</option> <option value='10'>10</option> <option value='15'>15 </option> <option value='20'> 20</option> <option value='25'>25</option> <option value='30'>30</option> <option value='35'>35</option> < /select><span>Goto page : <select name='GotoPage' onChange='GotoPg(this)'> <<<<<<<COMPUTED VALUE 1 >>>>>>>> </select> </span></td> </tr> </td> </table> <<<COMPUTED VALUE 1>>>>: contains: Total:=@Count(@DbColumn ("";"";@Subset(@ViewTitle;-1);1)); Viewname:=@Subset(@ViewTitle;-1); cnt:=@ToNumber(@UrlQueryString("count")); @If(cnt=0;@Return("");""); Start:=@ToNumber(@UrlQueryString("start")); Limit:=@Text(Total/cnt); LastPagelimit:=@If(@Contains(Limit;"."); @Integer(@ToNumber(Limit))+1; @Integer(@ToNumber(Limit))); HTML:="<option value=''> --Select--</option>"; @For(i:=1;i<=LastPagelimit;i:=i+1; HTML:=HTML+"<option value='"+ @Text(i)+"'>"+@Text(i)+"</option>") ; HTML
Step 3: Add this pagination bar:
<div id='pagination' align='center'> <<<< COMPUTED VALUE 2>>>> </div> <<<< COMPUTED VALUE 2>>>> should contain this: Total:=@Count(@DbColumn ("";"";@Subset(@ViewTitle;-1);1)); Viewname:=@Subset(@ViewTitle;-1); cnt:=@ToNumber(@UrlQueryString("count")); @If(cnt=0;@Return("");""); Start:=@ToNumber(@UrlQueryString("start")); Limit:=@Text(Total/cnt); LastPagelimit:=@If(@Contains(Limit;"."); @Integer(@ToNumber(Limit))+1;@Integer (@ToNumber(Limit))); Maxlimit:=@If(@Contains(Limit;".");@Integer (@ToNumber(Limit))+1; @Integer(@ToNumber(Limit))); MaxLimit:=@ToNumber(@If(@ToNumber (maxLimit) >10;10;Maxlimit)); pageNumber:= @Integer(((Start-1)/cnt) / Maxlimit); FirstPage:=@Repeat(" ";0) +"<a href='./"+Viewname+ "?openview&start=1&count="+@Text(cnt)+" '>First </a> "; LastPage:="<a href='./"+ Viewname+"?openview&start=" +@Text(((LastPagelimit-1)*cnt)+1) +"&count="+@Text(cnt)+" '> Last </a>"; Fromcnt:=pageNumber*Maxlimit+1; ToCnt:=Fromcnt+Maxlimit-1; ToCnt:=@If( (Fromcnt+Maxlimit-1)*cnt >= Total;LastpageLimit;Fromcnt+Maxlimit-1); @For(i:=Fromcnt;i<=Tocnt; i:=i+1; @Do( Newstart:=@Text(((i-1)*cnt)+1); FrontAHref:="<a href='./"+Viewname+" ?openview&start="+Newstart+"&count="+ @Text(cnt)+"'>"; RearAHref:="</a> "; @If((start-1)/cnt =i-1 ; h:=h+"<font color='red'><b>"+@Text(i) +" <b></font>"; h:=h+FrontAHref +@Text(i) + RearAHref) ) ); NextDisplay:=@If(start+cnt > @ToNumber(lastpagelimit)*cnt;"none";""); NextPage:="<a style='display:"+ nextDisplay +" ' href='./"+Viewname +"?openview&start=" + @Text( ((start)+cnt)) + "&count="+@Text(cnt)+"'><img src='rightArrow.jpg' align='bottom' style='border:0px' alt='Next'></img></a>"; PrevDisplay:=@If(start<=1;"none";""); PrevPage:="<a style='display:"+ PrevDisplay +" ' href='./"+Viewname +"?openview&start=" + @Text( ((start)-cnt)) +"&count="+@Text(cnt)+"'> <img src='leftArrow.jpg' align='bottom' +style='border:0px' alt= 'Previous'></img></a>"; FirstPage +PrevPage +" " + h + +" " + NextPage + LastPage
Step 4: Add this computed value below the table displaying documents (showing 51-100 Records of 361 ):
<div align='center' id='ShowRecs' style="display:none1" ><br> <<<<<COMPUTED VALUE 3 >>>>> </div> <<<<<COMPUTED VALUE 3 >>>>> should contain this: Total:=@Count(@DbColumn ("";"";@Subset(@ViewTitle;-1);1)); Start:=@UrlQueryString("start"); cnt:=@UrlQueryString("count"); cnt:=@ToNumber(cnt)+@ToNumber(Start)-1; cnt:=@Text(@If(cnt>Total;Total;cnt)); var1:="Showing " + start +" - " + cnt +" of " + @Text(Total) + " Records."; var2:="Showing " + start +" of " + @Text(Total) + " Records."; @If(cnt=start;var2;var1)
Step 5: Add these JavaScript functions in the JavaScript header; they are used in the combobox onChange event:
function DocsPerPage() { location.href='./'+document.forms[0]. ViewName.value+'?openview&start=1&count=' +document.forms[0].Pages.value } function GotoPg(obj) { PageNumber=obj.options[ obj.selectedIndex].value-1 start=PageNumber * document.forms[0].ParamCount.value+1 url='./' +document.forms[0].ViewName.value +'?openview&start='+start + '&count=' +document.forms[0].ParamCount.value location.href=url }
Step 6: This is the most important step, as it will go into an infinite loop for the computation and you'll get a "memory out of space" error.
Add this "Onload" event of the form: if(location.href.indexOf("count")<0) location.href='./'+document.forms[0] .ViewName.value+'?openview&start=1&count=5'
Note: Your view must be opened using the URL parameters: start=1 and count=X. For example:http://server:port/Demo.nsf/All?openview&start=1&count=5
You can also place the <<<<<computed value 2 >>> above and below the table containing the documents.
Do you have comments on this tip? Let us know.
Related information from SearchDomino.com:
- Tip: Improve the performance of Domino Web forms
- Tip: How to create non-scrolling Lotus Domino view headers on the Web
- FAQ: Formula language for Lotus Notes and Domino
- Tutorial: An introduction to Formula language for Lotus Notes
- Reference Center: Web development tips and resources
This tip was submitted to the SearchDomino.com tip library by member Hemang Kapadia. Please let others know how useful it is via the rating scale below. Do you have a useful Lotus Notes, Domino, Workplace or WebSphere tip or code snippet to share? Submit it to our monthly tip contest and you could win a prize.