class sap.ui.model.Filter

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

Filter for the list binding.


Constructor

Constructor for Filter.

You either pass a single object literal with the filter parameters or use the individual constructor arguments. No matter which variant is used, only certain combinations of parameters are supported (the following list uses the names from the object literal):

An error will be logged to the console if an invalid combination of parameters is provided.

Please note that a model implementation may not support a custom filter function, e.g. if the model does not perform client-side filtering. It also depends on the model implementation if the filtering is case sensitive or not. Client models filter case insensitive compared to the OData models which filter case sensitive by default. See particular model documentation for details.

The filter operators "Any" and "All" are only supported in V4 OData models. When creating a filter instance with these filter operators, the argument variable only accepts a string identifier and condition needs to be another filter instance.

new sap.ui.model.Filter(vFilterInfo, vOperator?, vValue1?, vValue2?)
Param Type Default Value Description
vFilterInfo object string sap.ui.model.Filter[]

Filter info object or a path or an array of filters

path? string

Binding path for this filter

test? function(any) : boolean

Function used for the client-side filtering of items. It should return a Boolean indicating whether the current item passes the filter. If no test function is given, a default test function is used, based on the given filter operator and the comparator function.

comparator? function(any,any) : number

Function used to compare two values for equality and order during client-side filtering. Two values are given as parameters. The function is expected to return:

  • a negative number if the first value is smaller than the second value,
  • 0 if the two values are equal,
  • a positive number if the first value is larger than the second value,
  • NaN for non-comparable values.
If no function is given, sap.ui.model.Filter.defaultComparator is used.

operator? sap.ui.model.FilterOperator

Operator used for the filter

value1? any

First value to use with the given filter operator

value2? any

Second value to use with the given filter operator, used only for the "BT" between and "NB" not between filter operators

variable? string

The variable name used in lambda operators ("Any" and "All")

condition? sap.ui.model.Filter

A filter instance which will be used as the condition for lambda operators ("Any" and "All")

filters? sap.ui.model.Filter[]

An array of filters on which the logical conjunction is applied

and? boolean false

Indicates whether an "AND" logical conjunction is applied on the filters. If it's not set or set to false, an "OR" conjunction is applied.

caseSensitive? boolean

Indicates whether a string value should be compared case sensitive or not. The handling of undefined depends on the model implementation.

vOperator? sap.ui.model.FilterOperator function(any) : boolean boolean

Either a filter operator or a custom filter function or a boolean flag that defines how to combine multiple filters

vValue1? any

First value to use with the given filter operator

vValue2? any

Second value to use with the given filter operator, used only for the "BT" between and "NB" not between filter operators


Methods Overview

Method Description
sap.ui.model.Filter.defaultComparator

Compares two values

This is the default comparator function used for client-side filtering, 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 neither less or greater, and string values where localeCompare is used.

The comparator method returns -1, 0, 1 for comparable values and NaN for non-comparable values.

sap.ui.model.Filter.extend

Creates a new subclass of class sap.ui.model.Filter 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.

getComparator

Returns the comparator function as provided on construction of this filter, see sap.ui.model.Filter#constructor, parameter vFilterInfo.comparator.

getCondition

Returns the filter instance which is used as the condition for lambda operators, see sap.ui.model.Filter#constructor, parameter vFilterInfo.condition.

getFilters

Returns the array of filters as specified on construction of this filter, see sap.ui.model.Filter#constructor, parameter vFilterInfo.filters

sap.ui.model.Filter.getMetadata

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

getOperator

Returns the filter operator used for this filter, see sap.ui.model.Filter#constructor, parameter vFilterInfo.operator or vOperator.

getPath

Returns the binding path for this filter, see sap.ui.model.Filter#constructor, parameter vFilterInfo or vFilterInfo.path.

getTest

Returns the test function which is used to filter the items, see sap.ui.model.Filter#constructor, parameter vFilterInfo.test.

getValue1

Returns the first value that is used with the given filter operator, see sap.ui.model.Filter#constructor, parameter vFilterInfo.value1 or vValue1.

getValue2

Returns the second value that is used with the given filter operator, see sap.ui.model.Filter#constructor, parameter vFilterInfo.value2 or vValue2.

getVariable

Returns the variable name used in lambda operators, see sap.ui.model.Filter#constructor, parameter vFilterInfo.variable.

isAnd

Indicates whether an "AND" logical conjunction is applied on the filters, see sap.ui.model.Filter#constructor, parameter vFilterInfo.and.

isCaseSensitive

Indicates whether a string value should be compared case sensitive, see sap.ui.model.Filter#constructor, parameter vFilterInfo.caseSensitive.

sap.ui.model.Filter.defaultComparator

Compares two values

This is the default comparator function used for client-side filtering, 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 neither less or greater, and string values where localeCompare is used.

The comparator method returns -1, 0, 1 for comparable values and NaN for non-comparable values.

Param Type DefaultValue Description
a any

the first value to compare

b any

the second value to compare

sap.ui.model.Filter.extend

Creates a new subclass of class sap.ui.model.Filter 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

getComparator

Returns the comparator function as provided on construction of this filter, see sap.ui.model.Filter#constructor, parameter vFilterInfo.comparator.

getCondition

Returns the filter instance which is used as the condition for lambda operators, see sap.ui.model.Filter#constructor, parameter vFilterInfo.condition.

getFilters

Returns the array of filters as specified on construction of this filter, see sap.ui.model.Filter#constructor, parameter vFilterInfo.filters

sap.ui.model.Filter.getMetadata

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

getOperator

Returns the filter operator used for this filter, see sap.ui.model.Filter#constructor, parameter vFilterInfo.operator or vOperator.

getPath

Returns the binding path for this filter, see sap.ui.model.Filter#constructor, parameter vFilterInfo or vFilterInfo.path.

getTest

Returns the test function which is used to filter the items, see sap.ui.model.Filter#constructor, parameter vFilterInfo.test.

getValue1

Returns the first value that is used with the given filter operator, see sap.ui.model.Filter#constructor, parameter vFilterInfo.value1 or vValue1.

getValue2

Returns the second value that is used with the given filter operator, see sap.ui.model.Filter#constructor, parameter vFilterInfo.value2 or vValue2.

getVariable

Returns the variable name used in lambda operators, see sap.ui.model.Filter#constructor, parameter vFilterInfo.variable.

isAnd

Indicates whether an "AND" logical conjunction is applied on the filters, see sap.ui.model.Filter#constructor, parameter vFilterInfo.and.

isCaseSensitive

Indicates whether a string value should be compared case sensitive, see sap.ui.model.Filter#constructor, parameter vFilterInfo.caseSensitive.