Filtering and sorting

The domain model allows you to define the (default) sort order for select queries and also allows you to define which filters may be applied. At runtime it is possible to change the sort order or enable the filters.

Sorting

The sort order can which needs to be determined for all selects on a specific table can be changed at runtime. This can be done with code like


SelectorsState.setSorting( "CocoonMan", "firstName" );

This example indicates that all selectors for the "CocoonMan" table need to be sorted on the "firstName" field. Note that the sorting affects all select queries on that table. The table name should always be the root of the hierarchy. It has no effect when applied to a table which has a parent template.
You can reverse the sort order by preceding the field name with a minus sign. It is also possible to specify combined sort order (several fields) or include some of the automatically included metadata fields.


SelectorsState.setSorting( "CocoonMan", "-firstName,EQUANDA_MODIFIED" );

To clear the sorting back to the default (as defined in the object model), reset the value to null.


SelectorsState.setSorting( "CocoonMan", null );

Filtering

Similar to sorting, it is also possible to filter select results. You need to define in the domain model which filters can be applied and what the effect of a filter is. For example (this one comes from the test suite), for the following table


<?xml version="1.0" encoding="ISO-8859-1"?>
<!DOCTYPE table SYSTEM "equanda.dtd">

<table name="FootballPlayer">
<data-filter name="GoalkeepersFilter"><filter-query where="o.goalkeeper=1"/></data-filter>
<data-filter name="GoalkeepersHideFilter"><filter-query where="o.goalkeeper=0"/></data-filter>
<data-filter name="Team"><filter-query where="o.team=${}"/></data-filter>
<data-filter name="Tag"><filter-query from="IN (o.tags) tags" where="tags.tags=${}"/></data-filter>
<security-role-remove>LocalUser,AdminUser</security-role-remove>
<page>
<field name="Name" type="string">
<display/>
</field>
<field name="Team"/>
<field name="Goalkeeper" type="boolean"/>
<field name="Tags" type="string">
<multiple/>
</field>
</page>
<select name="All" order="EQUANDA_MODIFIED"/>
<select name="FieldPlayers">
<description>This will be hidden if GoalkeepersHideFilter is set</description>
<view-filter>GoalkeepersHideFilter</view-filter>
</select>
</table>

Filters are defined by name. Once a filter is assigned a not-null value it is applied to the selector in the table on which the filter is defined. The effect on the select queries is specified in the "filter-query" tag.
Inside the from and where parts, you can use "${}
", this will be replaced by the filter value when the query is processed. Activating a filter is easy.


SelectorsState.setFilter( "Team", "Standard" );

You can deactiviate the filter by resetting to "null". Note that a filters are thread specific (note that it is particularly important in a servlet environment where not resetting a filter can have unexpected results in other servlet requests processed by the same thread). Their settings are passed on to the server side in a client-server environment.

  • 1. Filtering and sorting
  • 1.1. Sorting
  • 1.2. Filtering