Sorting can be enabled for custom columns by setting two mandatory attributes in the
gridcolumn definition. The attribute sortable
has to be set to true
to enable sorting. The attribute sortField
has to specify the Solr index column
that should be used for sorting.
<gridcolumn id="creator" header="Creator" sortable="true" dataIndex="creator" u:sortField="creator"/>
Example 7.43. Two additional attributes for sorting.
For extended configuration purposes there are two optional attributes. The attribute
extendOrderBy
enables sorting by more than one column. The value of the attribute
is a function which returns an array with additional sort criteria. The function will get two
parameters. The first parameter is the primary sort field, the second parameter is the primary
sort direction. The following example does not only sort by creator but also by name and
creation date. The value for the function parameter field
is "creator", the value
of the parameter direction
depends on the user's choice and can be
"asc" or "desc".
<gridcolumn id="creator" header="Creator" sortable="true" dataIndex="creator" u:sortField="creator" u:extendOrderBy="{ function(field:String, direction:String):Array { var orderBys:Array = []; orderBys.push('name ' + direction); orderBys.push('creationdate ' + direction); return orderBys; } }"/>
Example 7.44. Optional extendOrderBy
Attribute for sort by more
than one column.
The optional attribute sortDirection
enables you to restrict the sort direction to only
one direction. This is useful if sorting does only make sense in one direction. For example a
user is usually not interested in the less relevant search result. So you want to disable
sorting for relevance ascending. Possible attribute values are "asc" or
"desc" where the value is the enabled sort direction.
<gridcolumn header="Relevance" id="score" dataIndex="score" sortable="true" u:sortField="score" u:sortDirection="desc"/>
Example 7.45. Optional sortDirection
Attribute to enable only one
sort direction.
You can make even hidden grid columns sortable. Hidden columns are
not shown in the grid but users can select them from the sort drop down field. This is useful
if columns do not have meaningful values (again relevance for example) or if you just do not
want to blow up the grid too much. Hidden columns that do not have their hideable
config option set to false
can also be unhidden by the user using the grid header
menu.
At last you can define one default sort column for each list in the collection view.
The default sort column will be used when the user has not specified a sort criteria.
To configure add the attribute defaultSortColumn
with value true
. For more fine grained configuration the attribute defaultSortDirection
can be set to asc
or desc
to sort ascending or descending by default.
<gridcolumn id="creator" header="Creator" sortable="true" dataIndex="creator" u:defaultSortColumn="true" u:defaultSortDirection="desc" />
Example 7.46. defaultSortColumn
Attribute to configure one column as the default for sorting.