Tip #7: simple view navigation


I like to present “semi-intelligent” view navigation options to users in Domino applications. You know the kind of thing: you show 20 documents at a time, and provide a “Previous / Next” set of links. But it doesn’t make sense to have a “Previous” link on the first page of documents. Nor does it make sense to present a “Next” option to the user when there are no more documents. All they’re gonna get is that "No Documents Found" message.

The form

OK, so I’m assuming you’re using $$ViewTemplate forms for your views. I would suggest adding a subform to these forms to provide the view navigation, and dumping all the relevant code in there. As this is going to be a subform, and therefore the same for all $$ViewTemplate forms, you will also need a field (in this example called txtViewName) to the forms. This field should compute to the name of the view the parent form holds (i.e. it’s full name or alias). Why you should do this will become clear I hope.

Now to the subform. You’ll need some hidden computed for display fields in it as detailed below. The first two you probably won’t need to include here, as I imagine you already have them elsewhere in your web-facing forms eh?

  • Start Compute this field to itself. So long as you’re using the &Start parameter in your query string, it’ll work
  • Count Compute this field to itself. So long as you’re using the &Count parameter in your query string, it’ll work
  • numEndCount Code something like this (now you see why we have Start and Count):
numTmp1 := Start + (Count - 1);
numTmp := @If(@IsError(numTmp1); 0; numTmp1);
@If(numTmp < numTotal; numTmp; numTotal)
  • numTotal Code something like this:
numTemp := @Elements(@DbColumn( "Notes" : "NoCache"; ""; txtViewName; 2));
@If(@IsError(numTemp); 0; numTemp)

This looks up to the relevant view (here, it’s second column, but you can play with that), and essentially gets a count of docs in it, returning a zero if there’s an error. Now, this technique of performing a @DbLookup should give you a couple of ideas as to why this method isn’t fool-proof / as robust as one would like…

There, we’re nearly set now!

The navigation controls

What you do for these is up to you. Graphical hotspots, anchor references, whatever. The key thing is that each of them has some hide-when formula applied (I often place my navigation graphics in adjacent cells within a table — that way, the hide-when code will work). The hide-when code for the “Previous” option should look like this: Start = 1

Easy eh? For the “Next” option, it will look like this: numEndCount >= numTotal

End bit

Of course, you can use these fields for other things too. How about some computed text above the embedded view that says something like this:

Displaying 21 - 30 of 197 documents…

… or maybe hiding the view altogether, and revealing a custom message, when there’s no data in the view? Much nicer than No Documents Found eh? All very easy to do, so I won’t insult your intelligence by walking through them as well ;-)

Comments on this post are now closed.


I’m a software architect / developer / general IT wrangler specialising in web, mobile web and middleware using things like node.js, Java, C#, PHP, HTML5 and more.

Best described as a simpleton, but kindly. You can read more here.