XPages Data Views – Part 8: Sorting and Filtering

There are several properties available for searching and filtering a data view. In this post, I’ll show how to use them.

The Data View properties make a few of these features prominently available.

DataView8_A

Data View Series

Sort column

The Sort column property allows you to choose a column on which the data view should be sorted. The combobox will give you a list of all columns in the underlying view.

However, you need to be aware that the underlying view column must have that sort option available (“click oncolumn header to sort”) or it won’t work.

The data view will be sorted the way the underlying view is sorted by default. You can choose an existing column, but you can also compute the value.

To add even more flexibility to your view, you can provide links or a combobox to let the user choose the sort option.

Here’s how you can make it happen:

1) Put a combobox on the page with a list of columns that are viable sort options for the view. (You can event put it in one of the pager top facets of the data view to tie it in.)
2) Bind the combobox to a sessionScope variable
3) Set the onchange event of the combobox to trigger a partial refresh on the data view
4) Compute the Sort column property to return that sessionScope variable

Filter by column value

The Filter by column value property sets the keys property of the data source (which is also available on other view data sources).

You can enter or compute a value here that will set the ‘keys’ property and filter out the data based on the sorted column in the view, which is the default sorted column or the column defined in the Sort column property.

Just like with a search field, you can provide the user a field to type and filter the data. You can provide a highly flexible experience for the user if you allow them to choose both the sort column and the filter to apply to that column.

Search in view results

Searching and category filtering work the same as view data sources in several other data display controls. For an example of how to implement searching, take a look at this post I wrote about searching with the View Panel control.

Advertisements

4 responses to “XPages Data Views – Part 8: Sorting and Filtering”

  1. David Navarre says :

    Brad, in regards to filters, I don’t think it necessarily uses the Sort column when you’ve specified one. My example is a little different, as I used four columns to filter, then sorted using the fifth sorted column. http://lostinxpages.com/2013/05/06/filtering-source-views-for-use-in-xpages/

    • Brad Balassaitis says :

      In my testing, it does filter on the first sorted column in the view. I have a test data view with the filter hard coded to ‘N’. If the view is sorted by state, then it filters to states starting with ‘N’. If the view is sorted by the fullname column, then it filters based on names starting with ‘N’.

      If you don’t have a sort column defined in the data view, then it will filter based on the first sorted column in the underlying view. Your post shows a great example of how to filter based on multiple sorted columns in the underlying view. I think the filtering properties of the data source seem to always work on the sorted columns in the underlying view — I think the data view’s ‘Sort Column’ property provides the ability to change it because the view is sorting by a different column.

  2. Qaiser says :

    Thanks dear for showing details on view sorting. If I have multi value field containing few users abbreviated names. How can I filter data based on value of multivalue field in a view e.g. using @Contains or so.

    • Brad Balassaitis says :

      In that kind of case, you would probably need to compute the Search property with a query string that you build with code. You can use FIELD [FieldName] CONTAINS “SomeValue”

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: