XPages Data Views – Part 10: Nested Repeat in the Detail Section

The great benefit of the collapsible detail section in the Data View control is that you can make a lot more information available in the view, but not clutter the screen with it unless the user requests it. I’ve had several cases where I’ve created a repeat control in the detail section and used it to display information related to the main document. In this post, I’ll show how to do it.

Data View Series

Nested Repeat Control

Here’s an example from the NotesIn9 video I did on customizing the Data View control.

DataView10_A

The sample database has a list of companies and a list of stock prices documents related to each company. When the user expands a company in the Data View, they see the list of related stock prices (along with a company description).

Here are the steps:

  1. Set the var property of the data view to provide a handle to each entry
  2. Create a repeat control in the detail section. (Add a panel or div to the Detail section and add the repeat control within that container.)
  3. Compute the value of the repeat control (All properties > data > value) to retrieve the ID of the main document and use it to look up related documents to display in the repeat control

Here is the code that populates the repeat control:

var vwPrices:NotesView = database.getView('Prices');
if (rowHandle.isDocument()) {
  var companyID = rowHandle.getDocument().getItemValueString('CompanyID');
  var vecPrices:NotesViewEntryCollection = vwPrices.getAllEntriesByKey(companyID);
  return vecPrices;
} else {
  return null;
}

The key to making this happen is having the ability to retrieve the UNID of the main document when populating the repeat control. In this example, the var property of the Data View is set to rowHandle and it used in line 3 to retrieve the CompanyID.

In line 4, the list of related stock prices is looked up from a view.

In line 5, the viewEntryCollection of price documents is returned to be the source of the repeat control.

At this point, the repeat control has the data and you just need to add computed fields to display it like you would with any repeat control.

Advertisements

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s

%d bloggers like this: