Skip to main content link. Accesskey S

XPages Wiki

Submit Search

YouAtNotes XPages Wiki


Home > UI > Work with views

Work with views

ShowTable of Contents

DbColumn and DbLookup with result as guaranteed array and with a cache


@DbLookup has the issue that it returns a string when it found exactly one result, and an array when it found multiple results.
That means after each @DbLookup you have to check if your result is a string or an array if you want to process it further with JavaScript.

Maybe you want to do the same @DbLookup multiple times on your XPage, for example if you have a listbox which fills it's values from a @DbLookup, but should be hidden when there are no values. For that case it would be nice to have the result of the first @DbLookup cached and re-used when needed the second time.

Both requirements are solved with these functions:

function DbLookupArray(viewname, k, field) {
		if (requestScope.get("dblookuparray-"+viewname+"-"+k)) {
			return requestScope.get("dblookuparray-"+viewname+"-"+k);
		}
		var r = @DbLookup("", viewname, k, field);
		if (r && typeof r == "string") r = new Array(r);
		if (r) requestScope.put("dblookuparray-"+viewname+"-"+k, r);
		return r;
}

function DbColumnArray(viewname, column) {
		var k = "dbcolumnarray-"+viewname+column;
		if (requestScope.get(k)) {
			return requestScope.get(k);
		}
		var r = @DbColumn("", viewname, column);
		if (r && typeof r == "string") r = new Array(r);
		if (r) requestScope.put(k, r);
		return r;	
}

Display an icon in a view column


Have one column's value computed and use something like this:
(this example assums that you in the first column of your view there is a icon number).

var url:XSPUrl = new XSPUrl(database.getHttpURL());
var path = "/icons/vwicn";
var idx = viewEntry.getColumnValues().get(1);
if (idx < 10)
    path += ("00"+idx).left(3);
else if (idx < 100)
    path += ("0"+idx).left(3);
else
    path += idx.left(3);
path += ".gif";
url.setPath(path);
url.removeAllParameters();
return url.toString();


Alternate solution:
(found by Paul Withers

You can reference the icons directory with the string: "./ibmxpres/domino/icons". So you can use something like this in your column (assuming that your view has a column named "iconnr"):

"/.ibmxspres/domino/icons/vwicn" + @Right("00"+@Text(viewEntry.getColumnValue("iconnr")),3) + ".gif"

Search in a view with code to optimze the search query string


- Place a view on your XPage
- Place an input field with databinding: advanced: scoped variable: viewScope, var name ="query"
- In the view all properties: data: search: use this javascript:


var v:string = viewScope.get("query");
if (v != null) {
    v = v.toLowerCase();
    v = v.replace("\"", "");
    v = v.replace("(", "");
    v = v.replace(")", "");
    v = v.replace("[", "");
    v = v.replace("]", "");
  
    v = v.replace("$", "");   
    v = v.replace(" and ", " ");
     v = v.replace("{", "");
    v = v.replace("}", "");
    var a = v.split(" ");
    v = a.join(" and ");   
    v = v.replace("not", "\"not\"");
    v = v.replace("or", "\"or\"");
    v
}


This script
  • removes unwanted characters
  • combines single words with AND
  • removes the word OR from the query


This script does not honor a query entered in " yet.

Display data of a view inside another view like a join


See also Nathan's post
  • place view on your XPage
  • go to all properties, set var="viewRow"
  • set one column as "computed column" and set the value to a script


var key = viewRow.getColumnValue("title of a column");
var lookup = @DbLookup(@DbName, "viewname", key, 2);
return lookup

Customize the pager and translate the strings in a pager


The strings "previous" and "next" in the view's default pager is not localized and always displayed in english.
But you can create a custom pager with custom and computable labels:

- select pager style "custom"
- add some pager controls like "first", "previous" etc.
- in outline view navigate to the pager, there you can expand the pager and can access the pager controls
- in each pager control you can customize the label


See http://www-10.lotus.com/ldd/beta/ndnextdpp.nsf/5f27803bba85d8e285256bf10054620d/f328cf8b4930b58c85257535004ac3b0?OpenDocument for details and screenshots.

Set alternating row colors


Thanks to Mark Houghes

You can set alternate CSS classes for alternating rows in a view control. Select the view control -> all properties -> styling -> rowClasses and set two classes like "rowEven, rowOdd".

Use sortcolumn property


In the "all properties -> data -> datasource" section of the XPage there is a property "sortcolumn". With that you can define after which column the view should be sorted.
Since this is dynamic like all other properties, it's quite a nice feature.

Be aware that the property acts on the column titles (!), not on column numbers or programatic names (thanks Nathan T. Freeman for that tip).
And they have to be marked as "sortable" in the view design.

Be careful if you design views with all columns sortable! On large datasets that can cause much work for the "update" task on the Domino server.

Display column sums


See post from Steve Castledine

Remember position between page changes


If you come back to a page with a view control, the view control always starts at row 1 and does not remember it's former position.
You can solve that as follows:

1.) in the XPages beforeRenderResponse event, write code like this:

var c = getComponent("viewPanel");
if (c) {
	sessionScope.put("viewfirst"+view.getPageName(), c.first);
}


with "viewPanel" as ID of your view control. This code puts the position of the view into a sessionScope variable.

Now in your view control -> all properties -> first put this code:

var v = sessionScope.get("viewfirst"+view.getPageName());
if (v) return v;


The "first" property defines where the view control starts.

Hide view when search returned 0 and show other message


If a search on a view returns no documents, you want to show a "no documents found" message instead of an empty view.
Create a new panel with the "no documents found" message and set the "visible" property to:

getComponent("viewPanel").getRowCount() < 1


And on the view control, set the "visible" property to:

getComponent("viewPanel").getRowCount() > 0

See what's possible with Xpages.
Have a look at our ServiceCommunicator website
and the YouAtNotes Support.
Use  searchlotus.com  for news in the Web related to Lotus Notes and Domino,
and to search those sites.
Check  youatnotes.com  for great Lotus Notes, Domino and XPages software.
Did this wiki help you?
Did this saved you time? Express your gratitude by making a donation:
PayPal - The safer, easier way to pay online!