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.
Data View Series
- Part 1 – Overview
- Part 2 – Creating a Data View
- Part 3 – Collapsible Details
- Part 4 – Icon Columns
- Part 5 – Pager Add Rows Control
- Part 6 – Pager Save State Control
- Part 7 – Customized Summaries
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.