class sap.ui.model.Sorter

Control sample: sap.ui.model.Sorter
Visiblity: public
UX Guidelines:
Implements:
Available since: N/A
Module: sap/ui/model/Sorter
Application Component: CA-UI5-COR

Sorter for list bindings.

Instances of this class define the sort order for a list binding.


Constructor

Constructor for Sorter.

new sap.ui.model.Sorter(sPath, bDescending?, vGroup?, fnComparator?)
Param Type Default Value Description
sPath string

the binding path used for sorting

bDescending? boolean false

whether the sort order should be descending

vGroup? boolean function

configure grouping of the content, can either be true to enable grouping based on the raw model property value, or a function which calculates the group value out of the context (e.g. oContext.getProperty("date").getYear() for year grouping). The control needs to implement the grouping behaviour for the aggregation which you want to group. In case a function is provided it must either return a primitive type value as the group key or an object containing a "key" property and additional properties needed for group visualization. This object or the object with the primitive type return value as "key" property is passed to the groupHeaderFactory function that has been specified to create the group header for the control aggregation; see sap.ui.base.ManagedObject#bindAggregation. Note: Grouping is only possible (and only makes sense) for the primary sort property.

fnComparator? function

A custom comparator function, which is used for client-side sorting instead of the default comparator method. Information about parameters and expected return values of such a method can be found in the default comparator documentation. Note: Custom comparator functions are meant to be used on the client. Models that implement sorting in the backend usually don't support custom comparator functions. Consult the documentation of the specific model implementation.


Methods Overview

Method Description
sap.ui.model.Sorter.defaultComparator

Compares two values

This is the default comparator function used for clientside sorting, if no custom comparator is given in the constructor. It does compare just by using equal/less than/greater than with automatic type casting, except for null values, which are last in ascending order, and string values where localeCompare is used.

The comparator method returns -1, 0 or 1, depending on the order of the two items and is suitable to be used as a comparator method for Array.sort.

sap.ui.model.Sorter.extend

Creates a new subclass of class sap.ui.model.Sorter with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.base.Object.extend.

getGroup

Returns a group object, at least containing a key property for group detection. May contain additional properties as provided by a custom group function.

getGroupFunction

Returns the group function of this Sorter. If grouping is not enabled on this Sorter, it will return undefined, if no explicit group function has been defined the default group function is returned. The returned function is bound to its Sorter, so it will group according to its own property path, even if it is used in the context of another Sorter.

sap.ui.model.Sorter.getMetadata

Returns a metadata object for class sap.ui.model.Sorter.

sap.ui.model.Sorter.defaultComparator

Compares two values

This is the default comparator function used for clientside sorting, if no custom comparator is given in the constructor. It does compare just by using equal/less than/greater than with automatic type casting, except for null values, which are last in ascending order, and string values where localeCompare is used.

The comparator method returns -1, 0 or 1, depending on the order of the two items and is suitable to be used as a comparator method for Array.sort.

Param Type DefaultValue Description
a any

the first value to compare

b any

the second value to compare

sap.ui.model.Sorter.extend

Creates a new subclass of class sap.ui.model.Sorter with name sClassName and enriches it with the information contained in oClassInfo.

oClassInfo might contain the same kind of information as described in sap.ui.base.Object.extend.

Param Type DefaultValue Description
sClassName string

Name of the class being created

oClassInfo object

Object literal with information about the class

FNMetaImpl function

Constructor function for the metadata object; if not given, it defaults to the metadata implementation used by this class

getGroup

Returns a group object, at least containing a key property for group detection. May contain additional properties as provided by a custom group function.

Param Type DefaultValue Description
oContext sap.ui.model.Context

the binding context

getGroupFunction

Returns the group function of this Sorter. If grouping is not enabled on this Sorter, it will return undefined, if no explicit group function has been defined the default group function is returned. The returned function is bound to its Sorter, so it will group according to its own property path, even if it is used in the context of another Sorter.

sap.ui.model.Sorter.getMetadata

Returns a metadata object for class sap.ui.model.Sorter.