Home > Domino Tips > Developer > JavaScript > Create link groups for search results or a view
Domino Tips:
EMAIL THIS
 TIPS & NEWSLETTERS TOPICS 

JAVASCRIPT

Create link groups for search results or a view


Eva Valenta
09.15.2003
Rating: -4.29- (out of 5) Hall of fame tip of the month winner


Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   


This JavaScript function may be used to create the link groups for search results or for a view. For example:
Previous | 1 | 2 | 3 | Next

Code

Input parameters: total - the total number of documents in the view or search result format - the format of the generated links 0 (or omitted) generates page numbers, ex. Previous | 1 | 2 | 3 | Next 1 generates groups, ex.. Previous | 1 - 4 | 5 - 8 | 9 - 10 | Next when you call the original view the URL should include two parameters: &count will be used to calculate the intervals &start must be the last parameter in the URL defaults &count=30&start=1 place call to this function on the $$...template at the spot where you want the links to appear set the total passed to this function to TotalHits or use @DBLookup to set it to the number of documents in the view Place it on any $$viewtemplate or $$searchtemplate and pass the total to it.

/* ----------------------------------------------
------------------------------
return middle of the string
example:
middle('&count=25&start=1&', 
'&count=', '&') 
will return:
'25'
------------------------------------------------
-------------------------------*/
function middle(str, ina, inb){ // return 
middle of the string
//alert('middle function');
var startix = str.indexOf(ina);
var endix = str.indexOf(inb, 
startix + 1);
var newStr = '';
if (startix >= 0) { 
if (endix < 0) {endix = str.length;} 
newStr = str.substring(startix + 
ina.length, endix);
} else {newStr = ''; }
return newStr; 
} // end of function middle()
/* --------------------------------------------
---------------------------------
Generate links in groups
place this script on a $$viewtemplate 
or $$searchtemplate

Input parameters:
total - the total number of documents 
in the view or search result
format - the format of the generated links
0 (or omitted) generates page 
numbers, ex. Previous | 1 | 2 | 3 | Next 
1 generates groups, ex.. 
Previous | 1 - 4 | 5 - 8 | 9 - 10 | Next 
when you call the original view the 
URL should include two parameters:
&count will be used to calculate the
 intervals
&start must be the last parameter 
in the URL
defaults &count=30&start=1
place call to this function on 
the $$...template at the spot where 
you want the links to appear
set the total passed to this function 
to TotalHits or 
use @dbLookup to set it to the n
umber of documents in the view
-----------------------------------------------
-------------------------------*/
function generateLinks(total, format) 
{ // generate a range of links
//alert('generateLinks, total = ' + total); 
function makeLink(curStart, linkText) 
{ // create the <a> tag (internal 
function)
var tmpLink = '';
tmpLink = '<a '+ style + ' href="'
+ shortLoc + '&start=' + curStart + '" >' ;
tmpLink = tmpLink + linkText + '</a>';
return(tmpLink );
} // end of internal function makeLink

var loc = String(window.location.href); 
//alert('location=' + loc);
loc = loc.toLowerCase(); 
//alert('location.lowercase=' + loc);

var nextLink = 'Next';
var prevLink = 'Previous';
var style = '';
var links = ''; 
var ix = loc.indexOf('&start='); 
// &start= must be the last parameter
//alert('ix=' + ix); 
var shortLoc = loc;
if (ix < 0) { start = 1; }
else {
shortLoc = loc.substring(0,ix); 
start = parseInt(middle(loc, '&start=', 
'&'),10);
} 
ix = loc.indexOf('&count='); 
if (ix < 0) {
count = 30 ;
shortLoc = shortLoc + '&count=' +
 count;
}
else {
count = parseInt(middle(loc, 
'&count=', '&'),10);
}

nextStart = start + count;
prevStart = start - count;
if (nextStart < total) { nextLink = 
makeLink(nextStart, nextLink); }
if (prevStart > 0) { prevLink = 
makeLink(prevStart, prevLink); }

ix = total/count;
if (total % count == 0) {ix = ix - 1}; 
// set number of links

for (var j = 0; j <= ix; j++) { // create
 all the links
thisStart = j*count + 1;
thisEnd = thisStart + count - 1;
if (thisEnd > total) {thisEnd = total }
if (thisStart == start) {style = 'style=
"font-weight: bold" '; } 
else { style = ''}
if (format) {thisText = '' + thisStart + ' - 
' + thisEnd; }
else {thisText = String(j + 1); } 
links = links + ' | ' + makeLink(thisStart, 
thisText); 
}
document.writeln(prevLink + links + 
' | ' + nextLink);

} // end of function generateLinks()

Do you have comments on this tip? Let us know.


Rate this Tip
To rate tips, you must be a member of SearchDomino.com.
Register now to start rating these tips. Log in if you are already a member.




Digg This!    StumbleUpon Toolbar StumbleUpon    Bookmark with Delicious Del.icio.us   



RELATED CONTENT
JavaScript
Displaying a custom icon view column in Xpages
Trap JavaScript runtime errors in Domino Web apps
JavaScript workaround fixes Lotus Notes 8.x PostOpen event issue
Write HTML and JavaScript in Notes view rows and columns on the Web
JavaScript detects Web browser type and version in Notes/Domino 8.0.2
JavaScript creates a jump box on a Lotus Notes Web form
How to create dynamic JavaScript in Notes Domino without formulas
Trap an attachment path via the Domino file upload control field
Converting Lotus Notes views to XML documents using JavaScript
Prevent errors on iFramed pages with JavaScript

JavaScript for Lotus Notes Domino
Top 10 Lotus Notes/Domino development tips of 2009
Displaying a custom icon view column in Xpages
Trap JavaScript runtime errors in Domino Web apps
JavaScript workaround fixes Lotus Notes 8.x PostOpen event issue
Write HTML and JavaScript in Notes view rows and columns on the Web
JavaScript detects Web browser type and version in Notes/Domino 8.0.2
JavaScript creates a jump box on a Lotus Notes Web form
Top 10 Lotus Notes/Domino coding and development tips of 2008
How to create dynamic JavaScript in Notes Domino without formulas
Trap an attachment path via the Domino file upload control field

RELATED RESOURCES
2020software.com, trial software downloads for accounting software, ERP software, CRM software and business software systems
Search Bitpipe.com for the latest white papers and business webcasts
Whatis.com, the online computer dictionary

DISCLAIMER: Our Tips Exchange is a forum for you to share technical advice and expertise with your peers and to learn from other enterprise IT professionals. TechTarget provides the infrastructure to facilitate this sharing of information. However, we cannot guarantee the accuracy or validity of the material submitted. You agree that your use of the Ask The Expert services and your reliance on any questions, answers, information or other materials received through this Web site is at your own risk.



Domino & Lotus Notes Security Solutions: Authentication, Antispam, Encryption and Antivirus
HomeTopicsITKnowledge ExchangeTipsAsk the ExpertsMultimediaWhite PapersDomino IT Downloads
About Us  |  Contact Us  |  For Advertisers  |  For Business Partners  |  Site Index  |  RSS
SEARCH 
TechTarget provides technology professionals with the information they need to perform their jobs - from developing strategy, to making cost-effective purchase decisions and managing their organizations' technology projects - with its network of technology-specific websites, events and online magazines.

TechTarget Corporate Web Site  |  Media Kits  |  Site Map




All Rights Reserved, Copyright 1999 - 2010, TechTarget | Read our Privacy Policy
  TechTarget - The IT Media ROI Experts