XPages Tip: Filtering a View Data Source with URL Parameters

If you’re looking for a quick way to manipulate the data returned by a view data source, you can use URL parameters that match the property names. This allows you to effectively compute them without having to write code to compute the parameters. In this post, I’ll show several examples.

Sample View

In my sample database, I have a categorized view in the Notes client.

ViewDataSourceURLParams-1

I added a data source for this view to an XPages and dragged all of the columns on to the page to have it automatically create a view
panel.

http://www.server.com/myDB.nsf/MyPageName.xsp
ViewDataSourceURLParams-1b-XPage

Here’s the data source tag on the page — there are no computed properties.

<xp:this.data>
  <xp:dominoView var="view1" viewName="People"></xp:dominoView>
</xp:this.data>

Using URL Parameters to Filter the View

To filter the view, all you have to do is append URL parameters with the same name as a filtering property of the view data source.

To limit the data to a single category, add a categoryFilter parameter.

http://www.server.com/myDB.nsf/MyPageName.xsp?categoryFilter=Group 1
ViewDataSourceURLParams-2-categoryFilter

To execute a full-text search, add a search parameter. (The database must be full-text indexed or it will throw an error.) You can also include wildcards in the search parameter.

http://www.server.com/myDB.nsf/MyPageName.xsp?search=101
ViewDataSourceURLParams-3-Search

To filter the results based on the first sorted column in the view, use the keys parameter.

http://www.server.com/myDB.nsf/MyPageName.xsp?keys=Group 3

Other Actions

To set the view’s starting point, you can use the startKeys parameter. (Note: The view will continue on to the end after the starting point.)

http://www.server.com/myDB.nsf/MyPageName.xsp?startKeys=group 2

To expand or collapse categories in the view, use the expandLevel parameter.

http://www.server.com/myDB.nsf/MyPageName.xsp?expandLevel=1
ViewDataSourceURLParams-4-ExpandLevel

Miscellaneous Notes

These attributes work on the view data source and not specifically on the view panel, so it is useful on a repeat control or any other control that uses a view data source.

If your data source has ignoreRequestParameters set to true, then this will not work because it will – um – ignore the request parameters.

If you enter a parameter that doesn’t correspond exactly to a property name, then it will be ignored by the view data source.

Advertisements

Tags:

7 responses to “XPages Tip: Filtering a View Data Source with URL Parameters”

  1. Patrick Kwinten says :

    hmm some lightbox would have been great for displaying the images back & forw

  2. Ryan says :

    Did not know about the search parameter. Thank you!

  3. Steve Cochrane says :

    Thanks! In the old fashioned parameters, we had “SearchOrder” and many others. Any equivalent for sorting, by the 1st column or by a date field? My repeat control has search results from several other Notes applications, as well as many other features. Also, I won’t be able to change the sorting in the source views.

    Any ideas?

    Thanks!

    • Brad Balassaitis says :

      I’m not aware of a parameter to sort via URL. There’s a sortColumn option in a dominoView data source, so you could try that. However, don’t expect it to work if the underlying view doesn’t already have a sort for that column.

      You could create a custom REST service to provide the data and build it to handle any sorting that you need.

      Most of my applications over the past few years have used client-side grids as the primary data display mechanism. They generally come with built-in column sorting (with multiple levels), which is a much better user experience because it happens quickly on the client side once the data is downloaded. This lets users do whatever they want to filter or sort without having to change anything on the back end.

  4. jason says :

    Hi,

    I am in a situation where , I have a categorized view (by names), which has documents under its respective category. I have put a 2 combo boxes to filter the documents by Year and month.

    The backend view fist 2 columns are sorted the 3rd column is a categorize column.

    How can I effectively do this. Any guidance is appreciated. Thank you in advance

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: