class sap.ui.model.SelectionModel

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

This artefact is used by the table controls for handling selections. It is not associated with the model layer of UI5.


Constructor

Constructs an instance of an sap.ui.model.SelectionModel.

new sap.ui.model.SelectionModel(iSelectionMode)
Param Type Default Value Description
iSelectionMode int

sap.ui.model.SelectionModel.SINGLE_SELECTION or sap.ui.model.SelectionModel.MULTI_SELECTION


Methods Overview

Method Description
addSelectionInterval

Changes the selection to be the union of the current selection and the range between iFromIndex and iToIndex inclusive. If iFromIndex is smaller than iToIndex, both parameters are swapped.

In SINGLE_SELECTION selection mode, this is equivalent to calling setSelectionInterval, and only the second index is used.

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

attachSelectionChanged

Attaches event handler fnFunction to the selectionChanged event of this sap.ui.model.SelectionModel.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.model.SelectionModel itself.

clearSelection

Change the selection to the empty set and clears the lead selection.

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

detachSelectionChanged

Detaches event handler fnFunction from the selectionChanged event of this sap.ui.model.SelectionModel.

The passed function and listener object must match the ones used for event registration.

sap.ui.model.SelectionModel.extend

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

fireSelectionChanged

Fires event selectionChanged to attached listeners.

Expects following event parameters:

  • 'leadIndex' of type int Lead selection index.
  • 'rowIndices' of type int[] Other selected indices (if available)

getLeadSelectedIndex

Return the second index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().

sap.ui.model.SelectionModel.getMetadata

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

getSelectedIndices

Returns the selected indices as array.

getSelectionMode

Returns the current selection mode.

isSelectedIndex

Returns true if the specified index is selected.

moveSelectionInterval

Moves all selected indices starting at the position iStartIndex iMove items.

This can be used if new items are inserted to the item set and you want to keep the selection. To handle a deletion of items use sliceSelectionInterval.

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

removeSelectionInterval

Changes the selection to be the set difference of the current selection and the indices between iFromIndex and iToIndex inclusive. If iFromIndex is smaller than iToIndex, both parameters are swapped.

If the range of removed selection indices includes the current lead selection, then the lead selection will be unset (set to -1).

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

selectAll

Selects all rows up to the iToIndex.

If this call results in a change to the current selection, then a SelectionChanged event is fired.

setSelectionInterval

Changes the selection to be equal to the range iFromIndex and iToIndex inclusive. If iFromIndex is smaller than iToIndex, both parameters are swapped.

In SINGLE_SELECTION selection mode, only iToIndex is used.

If this call results in a change to the current selection, then a SelectionChanged event is fired.

setSelectionMode

Sets the selection mode. The following list describes the accepted selection modes:

  • sap.ui.model.SelectionModel.SINGLE_SELECTION - Only one list index can be selected at a time. In this mode, setSelectionInterval and addSelectionInterval are equivalent, both replacing the current selection with the index represented by the second argument (the "lead").
  • sap.ui.model.SelectionModel.MULTI_SELECTION - In this mode, there's no restriction on what can be selected.

sliceSelectionInterval

Slices a the indices between the two indices from the selection. If iFromIndex is smaller than iToIndex, both parameters are swapped.

If the range of removed selection indices includes the current lead selection, then the lead selection will be unset (set to -1).

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

addSelectionInterval

Changes the selection to be the union of the current selection and the range between iFromIndex and iToIndex inclusive. If iFromIndex is smaller than iToIndex, both parameters are swapped.

In SINGLE_SELECTION selection mode, this is equivalent to calling setSelectionInterval, and only the second index is used.

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

Param Type DefaultValue Description
iFromIndex int

one end of the interval.

iToIndex int

other end of the interval

attachSelectionChanged

Attaches event handler fnFunction to the selectionChanged event of this sap.ui.model.SelectionModel.

When called, the context of the event handler (its this) will be bound to oListener if specified, otherwise it will be bound to this sap.ui.model.SelectionModel itself.

Param Type DefaultValue Description
oData object

An application-specific payload object that will be passed to the event handler along with the event object when firing the event

fnFunction function

The function to be called, when the event occurs

oListener object

Context object to call the event handler with. Defaults to this SelectionModel itself

clearSelection

Change the selection to the empty set and clears the lead selection.

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

detachSelectionChanged

Detaches event handler fnFunction from the selectionChanged event of this sap.ui.model.SelectionModel.

The passed function and listener object must match the ones used for event registration.

Param Type DefaultValue Description
fnFunction function

The function to be called, when the event occurs

oListener object

Context object on which the given function had to be called

sap.ui.model.SelectionModel.extend

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

fireSelectionChanged

Fires event selectionChanged to attached listeners.

Expects following event parameters:

Param Type DefaultValue Description
oParameters object

Parameters to pass along with the event.

leadIndex int

Lead selection index

rowIndices int[]

Other selected indices (if available)

getLeadSelectedIndex

Return the second index argument from the most recent call to setSelectionInterval(), addSelectionInterval() or removeSelectionInterval().

sap.ui.model.SelectionModel.getMetadata

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

getSelectedIndices

Returns the selected indices as array.

getSelectionMode

Returns the current selection mode.

isSelectedIndex

Returns true if the specified index is selected.

Param Type DefaultValue Description
iIndex int

moveSelectionInterval

Moves all selected indices starting at the position iStartIndex iMove items.

This can be used if new items are inserted to the item set and you want to keep the selection. To handle a deletion of items use sliceSelectionInterval.

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

Param Type DefaultValue Description
iStartIndex int

start at this position

iMove int

removeSelectionInterval

Changes the selection to be the set difference of the current selection and the indices between iFromIndex and iToIndex inclusive. If iFromIndex is smaller than iToIndex, both parameters are swapped.

If the range of removed selection indices includes the current lead selection, then the lead selection will be unset (set to -1).

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

Param Type DefaultValue Description
iFromIndex int

one end of the interval.

iToIndex int

other end of the interval

selectAll

Selects all rows up to the iToIndex.

If this call results in a change to the current selection, then a SelectionChanged event is fired.

Param Type DefaultValue Description
iToIndex int

end of the interval

setSelectionInterval

Changes the selection to be equal to the range iFromIndex and iToIndex inclusive. If iFromIndex is smaller than iToIndex, both parameters are swapped.

In SINGLE_SELECTION selection mode, only iToIndex is used.

If this call results in a change to the current selection, then a SelectionChanged event is fired.

Param Type DefaultValue Description
iFromIndex int

one end of the interval.

iToIndex int

other end of the interval

setSelectionMode

Sets the selection mode. The following list describes the accepted selection modes:

Param Type DefaultValue Description
iSelectionMode int

selection mode

sliceSelectionInterval

Slices a the indices between the two indices from the selection. If iFromIndex is smaller than iToIndex, both parameters are swapped.

If the range of removed selection indices includes the current lead selection, then the lead selection will be unset (set to -1).

If this call results in a change to the current selection or lead selection, then a SelectionChanged event is fired.

Param Type DefaultValue Description
iFromIndex int

one end of the interval.

iToIndex int

other end of the interval