Search code examples
viewpaginationlotus-domino

Lotus Domino: View pagination on web


I read on many forums about how to implement a solution for view pagionation, but I didn't solve it.

I created $$ViewTemplateDefault containing some personalized hotspotbuttons for Next, Previous and a text field $$ViewBody. ( or, alternatively, an embedded view ).

Any tips and help will be really appreciated.

I will explain in a couple words, just to be clear:

So, initially: the first 30 lines will appear => in a right corner: Page 1.

If Next is clicked => the next 30 lines => Page 2. and so on.


Solution

  • Here is a working solution for categorized views too. It calculates the current page number based on the previous page number and uses cookies.

    Add to your form a Path-Thru HTML text <span id="pageNumber"></span > for the page number:

    enter image description here

    and add following code to form's onLoad event as Web/JavaScript:

    function getURLParameter(parameter) {
      return decodeURIComponent((new RegExp('[?|&]' + parameter + '=' + '([^&;]+?)(&|#|;|$)').exec(location.search) || [, ""])[1].replace(/\+/g, '%20')) || null;
    }
    function getCookie(cname) {
        var name = cname + "=";
        var ca = document.cookie.split(';');
        for(var i=0; i<ca.length; i++) {
            var c = ca[i].trim();
            if (c.indexOf(name)==0) return c.substring(name.length,c.length);
        }
        return "";
    }
    function compareStart(start1, start2) {
        var list1 = start1.split(".");
        var list2 = start2.split(".");
        for (i=0; i <100; i++) {
            var value1 = list1[i];
            var value2 = list2[i];
            if (value1 == null) {
                return value2 == null ? 0 : -1;
            } else if (value2 == null) {
                    return 1;
            }
            value1 = Math.round(value1);
            value2 = Math.round(value2);
            if (value1 !== value2) {
                return value1 < value2 ? -1 : 1;
            }
        }
    }
    var start = getURLParameter("Start");
    var page = "1";
    if  (start == null || start === "1") {
        window.name = Math.floor((Math.random()*10000)+1);
        start = "1";
    } else {
        page =  getCookie("page" + window.name);
        var oldStart = getCookie("start" + window.name);
        page = Math.round(page) + compareStart(start, oldStart);
    }
    document.getElementById('pageNumber').innerHTML = page;
    document.cookie = "page" + window.name + "=" + page;
    document.cookie = "start" + window.name + "=" + start;
    

    How does it work?

    The commands @DbCommand("Domino"; "ViewNextPage") and @DbCommand("Domino"; "ViewPreviousPage") return an URL with parameter "&Start=". This is the row number in view where the current page starts. For categorized views they return a hierarchical number like "&Start=1.2.4.2". That means that the view starts at the first main topic, subtopic 2, subsubtopic 4, document 2.

    This parameter "&Start=" gives us the possibility to recognize if user pressed "prev" or "next": we just compare the URL "&Start=" parameter of current and former page.

    For that, we have to remember the URL "&Start=" parameter and put it into a cookie "start".

    We also need to save the current page number. We put it into a cookie "page".

    At onload event we calculate the current page number based on previous page number:

    • if "&Start=" parameter is larger now then we add 1
    • if "&Start=" parameter is smaller now then we subtract 1
    • if "&Start=" parameter didn't change then we keep the former value

    If "&Start=" parameter is empty we know we are on page 1.

    Here is one other thing we have to deal with: cookies are saved per user session not per browser tab. That means, if we have two views open in browser same cookies "start" and "page" would be used. To avoid that, we have to add to cookie name something tab specific. I use for that a random four digit number and save it in window.name which is tab specific.