|
產生分頁連結 For Java Script /* ---------------------------------------------------------------------------- 產生分頁連結 For Java Script 在$$ViewTemplate or $$SearchTemplate裡一般我們能做的都是,[上一頁]或是[下一頁],想要產生像一般外面 網站有多頁面選擇的連結呢?呵呵~其實用公式也可做不過呢!需想很久要用到很多的公式還要對公式很熟才 能應用.難了吧!不過可別灰心我們現在介紹一個,簡單好用又不會吃Server系統效能的.我們只要把這篇文章 貼在欲用的套表裡的[Js Header]裡,然後要在產生的位置放置 generateLinks(30,0) >>參數為[視界總比數,顯示分頁格式] 視界總比數&分頁格式[0]:例如設定90則產生下方格是共三頁 [Previous | 1 | 2 | 3 | Next ] generateLinks(30,1) >> 視界總比數&分頁格式[1]:例如設定90則產生下方格是共三頁 [Previous | 1 - 30 | 31 - 60 | 61 - 90 | Next ] 各位讀者看出有啥不同了吧! 要注意的視界總比數可不是隨便給的是要從搜尋的總比數帶入或由公式算得總比數在讀取該欄位. 還有程式預設是30筆為一頁,讀者可自行直接修改或改成由參數帶入較佳 上下頁也可自己改很簡單,也可改帶參數的也不錯 另外介紹middle這個函數,他可以幫妳抓取兩特定字串的中間直 middle('欲抓的整個字串', '左字串', '右字串') 方便又簡單吧!在處理CGI的函數裡應該會常用到. 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 number 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() /* ---------------------------------------------------------------------------- 資料來源: http://searchdomino.techtarget.com/tip/1,289483,sid4_gci928463,00.html JAVASCRIPT Create link groups for search results or a view 15 Sep 2003 '==================================================== ' 本程式由『笑傲江湖工作室』撰寫 ' 使用Lotus Notes製作 R6 ' 作者:阿沖 huchung ling ' Mail: huchungling@power2.evernet.com.tw ' Web Site: http://Rnext.evernet.com.tw 'Working Together ' TRY IT.... 'the power of one '心是最大的戰場 ' 唯有不斷的學習 才是成功的關鍵 ‘921021 '==================================================== ‘作者保留著作權,並同意任何人以任何形式及方式轉載或引用並請註明出處保留作者資訊 -------------------------------------------------------------------------------*/
|