Class sap.m.SegmentedButtonModule: sap/m/SegmentedButton

extends Control
implements IFormContent

SegmentedButton is a horizontal control made of multiple buttons, which can display a title or an image. It automatically resizes the buttons to fit proportionally within the control. When no width is set, the control uses the available width.
Constructor Summary
new sap.m.SegmentedButton(sId?, mSettings?)Constructor for a new SegmentedButton.
Event Summary
select(oControlEvent)Fires when the user selects a button, which returns the ID and button object.
Events borrowed from class sap.ui.core.Control
Method Summary
sap.m.SegmentedButton.extend(sClassName, oClassInfo?, FNMetaImpl?)Creates a new subclass of class sap.m.SegmentedButton with name sClassName and enriches it with the information contained in oClassInfo.
sap.m.SegmentedButton.getMetadata()Returns a metadata object for class sap.m.SegmentedButton.
addAriaDescribedBy(vAriaDescribedBy)Adds some ariaDescribedBy into the association ariaDescribedBy.
addAriaLabelledBy(vAriaLabelledBy)Adds some ariaLabelledBy into the association ariaLabelledBy.
addItem(oItem, bSuppressInvalidate?)Adds item to items aggregation.
attachSelect(oData?, fnFunction, oListener?)Attaches event handler fnFunction to the select event of this sap.m.SegmentedButton.
bindItems(oBindingInfo)Binds aggregation items to model data.
bindSelectedKey(oBindingInfo)Binds property selectedKey to model data.
createButton(sText, sURI, bEnabled, sTextDirection?)Adds a Button with a text as title, a URI for an icon, enabled and textDirection.
destroyItems()Destroys all the items in the aggregation items.
detachSelect(fnFunction, oListener)Detaches event handler fnFunction from the select event of this sap.m.SegmentedButton.
fireSelect(mParameters?)Fires event select to attached listeners.
getAriaDescribedBy()Returns array of IDs of the elements which are the current targets of the association ariaDescribedBy.
getAriaLabelledBy()Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
getEnabled()Gets current value of property enabled.
getItems()Gets content of aggregation items.
getSelectedButton()ID of the element which is the current target of the association selectedButton, or null.
getSelectedKey()Gets the selectedKey and is usable only when the control is initiated with the items aggregation.
getWidth()Gets current value of property width.
indexOfItem(oItem)Checks for the provided sap.m.SegmentedButtonItem in the aggregation items.
insertItem(oItem, iIndex, bSuppressInvalidate?)Inserts item into items aggregation.
removeAllAriaDescribedBy()Removes all the controls in the association named ariaDescribedBy.
removeAllAriaLabelledBy()Removes all the controls in the association named ariaLabelledBy.
removeAllItems(bSuppressInvalidate?)Removes all items from items aggregation
removeAriaDescribedBy(vAriaDescribedBy)Removes an ariaDescribedBy from the association named ariaDescribedBy.
removeAriaLabelledBy(vAriaLabelledBy)Removes an ariaLabelledBy from the association named ariaLabelledBy.
removeItem(oItem, bSuppressInvalidate?)Removes an item from items aggregation.
setEnabled(bEnabled)Sets a new value for property enabled.
setSelectedButton(vButton)Setter for association selectedButton.
setSelectedKey(sKey)Sets the selectedKey and is usable only when the control is initiated with the items aggregation.
setWidth(sWidth)Sets a new value for property width.
unbindItems()Unbinds aggregation items from model data.
unbindSelectedKey()Unbinds property selectedKey from model data.
addButton(oButton)Adds some button to the aggregation buttons.
destroyButtons()Destroys all the buttons in the aggregation buttons.
getButtons()Gets content of aggregation buttons.
indexOfButton(oButton)Checks for the provided sap.m.Button in the aggregation buttons.
insertButton(oButton, iIndex)Inserts a button into the aggregation buttons.
removeAllButtons()Removes all the controls from the aggregation buttons.
removeButton(vButton)Removes a button from the aggregation buttons.
Constructor Detail
new sap.m.SegmentedButton(sId?, mSettings?)

Constructor for a new SegmentedButton.

Accepts an object literal mSettings that defines initial property values, aggregated and associated objects as well as event handlers. See sap.ui.base.ManagedObject for a general description of the syntax of the settings object.

The supported settings are:

  • Properties

  • Aggregations

    • buttons : sap.m.Button[] (default)
    • items : sap.m.SegmentedButtonItem[]

  • Associations

  • Events

    • select : fnListenerFunction or [fnListenerFunction, oListenerObject] or [oData, fnListenerFunction, oListenerObject]

In addition, all settings applicable to the base type sap.ui.core.Control can be used as well.

Parameters:
stringsId?ID for the new control, generated automatically if no ID is given
objectmSettings?Initial settings for the new control
Event Detail
select(oControlEvent)
Fires when the user selects a button, which returns the ID and button object.
Parameters:
sap.ui.base.EventoControlEvent
sap.ui.base.EventProvideroControlEvent.getSource
objectoControlEvent.getParameters
sap.m.ButtonoControlEvent.getParameters.buttonReference to the button, that has been selected.
stringoControlEvent.getParameters.idID of the button, which has been selected.
stringoControlEvent.getParameters.keyKey of the button, which has been selected. This property is only filled when the control is initiated with the items aggregation.
Method Detail
sap.m.SegmentedButton.extend(sClassName, oClassInfo?, FNMetaImpl?): function

Creates a new subclass of class sap.m.SegmentedButton 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.core.Control.extend.

Parameters:
stringsClassNameName of the class being created
objectoClassInfo?Object literal with information about the class
functionFNMetaImpl?Constructor function for the metadata object; if not given, it defaults to sap.ui.core.ElementMetadata
Returns:
functionCreated class / constructor function
sap.m.SegmentedButton.getMetadata(): sap.ui.base.Metadata
Returns a metadata object for class sap.m.SegmentedButton.
Returns:
sap.ui.base.MetadataMetadata object describing this class
addAriaDescribedBy(vAriaDescribedBy): sap.m.SegmentedButton
Adds some ariaDescribedBy into the association ariaDescribedBy.
Parameters:
sap.ui.core.ID|sap.ui.core.ControlvAriaDescribedBythe ariaDescribedBy to add; if empty, nothing is inserted
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
addAriaLabelledBy(vAriaLabelledBy): sap.m.SegmentedButton
Adds some ariaLabelledBy into the association ariaLabelledBy.
Parameters:
sap.ui.core.ID|sap.ui.core.ControlvAriaLabelledBythe ariaLabelledBy to add; if empty, nothing is inserted
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
addItem(oItem, bSuppressInvalidate?)
Adds item to items aggregation.
Parameters:
sap.m.SegmentedButtonItemoItemThe item to be added
booleanbSuppressInvalidate?, Default: falseIf true the control invalidation will be suppressed
attachSelect(oData?, fnFunction, oListener?): sap.m.SegmentedButton

Attaches event handler fnFunction to the select event of this sap.m.SegmentedButton.

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.m.SegmentedButton itself.

Fires when the user selects a button, which returns the ID and button object.

Parameters:
objectoData?An application-specific payload object that will be passed to the event handler along with the event object when firing the event
functionfnFunctionThe function to be called when the event occurs
objectoListener?Context object to call the event handler with. Defaults to this sap.m.SegmentedButton itself
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
bindItems(oBindingInfo): sap.m.SegmentedButton

Binds aggregation items to model data.

See ManagedObject.bindAggregation for a detailed description of the possible properties of oBindingInfo.

Parameters:
objectoBindingInfoThe binding information
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
Since:
1.28
bindSelectedKey(oBindingInfo): sap.m.SegmentedButton

Binds property selectedKey to model data.

See ManagedObject.bindProperty for a detailed description of the possible properties of oBindingInfo

Parameters:
objectoBindingInfoThe binding information
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
Since:
1.28.0
createButton(sText, sURI, bEnabled, sTextDirection?): sap.m.Button
Adds a Button with a text as title, a URI for an icon, enabled and textDirection. Only one is allowed.
Parameters:
stringsTextDefines the title text of the newly created Button
sap.ui.core.URIsURIIcon to be displayed as graphical element within the Button. Density related image will be loaded if image with density awareness name in format [imageName]@[densityValue].[extension] is provided.
booleanbEnabledEnables the control (default is true). Buttons that are disabled have other colors than enabled ones, depending on custom settings.
sap.ui.core.TextDirectionsTextDirection?Element's text directionality with enumerated options
Returns:
sap.m.ButtonThe created Button
Since:
1.28.0
destroyItems(): sap.m.SegmentedButton
Destroys all the items in the aggregation items.
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
Since:
1.28
detachSelect(fnFunction, oListener): sap.m.SegmentedButton

Detaches event handler fnFunction from the select event of this sap.m.SegmentedButton.

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

Parameters:
functionfnFunctionThe function to be called, when the event occurs
objectoListenerContext object on which the given function had to be called
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
fireSelect(mParameters?): sap.m.SegmentedButton
Fires event select to attached listeners.
Parameters:
objectmParameters?Parameters to pass along with the event
sap.m.ButtonmParameters.button?Reference to the button, that has been selected.
stringmParameters.id?ID of the button, which has been selected.
stringmParameters.key?Key of the button, which has been selected. This property is only filled when the control is initiated with the items aggregation.
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
getAriaDescribedBy(): sap.ui.core.ID[]
Returns array of IDs of the elements which are the current targets of the association ariaDescribedBy.
Returns:
sap.ui.core.ID[]
getAriaLabelledBy(): sap.ui.core.ID[]
Returns array of IDs of the elements which are the current targets of the association ariaLabelledBy.
Returns:
sap.ui.core.ID[]
getEnabled(): boolean

Gets current value of property enabled.

Disables all the buttons in the SegmentedButton control. When disabled all the buttons look grey and you cannot focus or click on them.

Default value is true.

Returns:
booleanValue of property enabled

Gets content of aggregation items.

Aggregation of items to be displayed. The items set in this aggregation are used as an interface for the buttons displayed by the control. The "items" and "buttons" aggregations should NOT be used simultaneously as it causes the control to work incorrectly.

Returns:
sap.m.SegmentedButtonItem[]
Since:
1.28
getSelectedButton(): sap.ui.core.ID
ID of the element which is the current target of the association selectedButton, or null.
Returns:
sap.ui.core.ID
getSelectedKey(): string
Gets the selectedKey and is usable only when the control is initiated with the items aggregation.
Returns:
stringCurrent selected key
Since:
1.28
getWidth(): sap.ui.core.CSSSize

Gets current value of property width.

Defines the width of the SegmentedButton control. If not set, it uses the minimum required width to make all buttons inside of the same size (based on the biggest button).

Returns:
sap.ui.core.CSSSizeValue of property width
indexOfItem(oItem): int
Checks for the provided sap.m.SegmentedButtonItem in the aggregation items. and returns its index if found or -1 otherwise.
Parameters:
sap.m.SegmentedButtonItemoItemThe item whose index is looked for
Returns:
intThe index of the provided control in the aggregation if found, or -1 otherwise
Since:
1.28
insertItem(oItem, iIndex, bSuppressInvalidate?)
Inserts item into items aggregation.
Parameters:
sap.m.SegmentedButtonItemoItemThe item to be inserted
intiIndexindex the item should be inserted at
booleanbSuppressInvalidate?, Default: falseIf true the control invalidation will be suppressed
removeAllAriaDescribedBy(): sap.ui.core.ID[]
Removes all the controls in the association named ariaDescribedBy.
Returns:
sap.ui.core.ID[]An array of the removed elements (might be empty)
removeAllAriaLabelledBy(): sap.ui.core.ID[]
Removes all the controls in the association named ariaLabelledBy.
Returns:
sap.ui.core.ID[]An array of the removed elements (might be empty)
removeAllItems(bSuppressInvalidate?)
Removes all items from items aggregation
Parameters:
booleanbSuppressInvalidate?, Default: falseIf true the control invalidation will be suppressed
removeAriaDescribedBy(vAriaDescribedBy): sap.ui.core.ID
Removes an ariaDescribedBy from the association named ariaDescribedBy.
Parameters:
int|sap.ui.core.ID|sap.ui.core.ControlvAriaDescribedByThe ariaDescribedBy to be removed or its index or ID
Returns:
sap.ui.core.IDThe removed ariaDescribedBy or null
removeAriaLabelledBy(vAriaLabelledBy): sap.ui.core.ID
Removes an ariaLabelledBy from the association named ariaLabelledBy.
Parameters:
int|sap.ui.core.ID|sap.ui.core.ControlvAriaLabelledByThe ariaLabelledBy to be removed or its index or ID
Returns:
sap.ui.core.IDThe removed ariaLabelledBy or null
removeItem(oItem, bSuppressInvalidate?)
Removes an item from items aggregation.
Parameters:
sap.m.SegmentedButtonItemoItemThe item to be removed
booleanbSuppressInvalidate?, Default: falseIf true the control invalidation will be suppressed
setEnabled(bEnabled): sap.m.SegmentedButton

Sets a new value for property enabled.

Disables all the buttons in the SegmentedButton control. When disabled all the buttons look grey and you cannot focus or click on them.

When called with a value of null or undefined, the default value of the property will be restored.

Default value is true.

Parameters:
booleanbEnabledNew value for property enabled
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
setSelectedButton(vButton): sap.m.SegmentedButton
Setter for association selectedButton.
Parameters:
string|sap.m.Button|null|undefinedvButtonNew value for association setSelectedButton An sap.m.Button instance which becomes the new target of this selectedButton association. Alternatively, the ID of an sap.m.Button instance may be given as a string. If the value of null, undefined, or an empty string is provided the first item will be selected.
Returns:
sap.m.SegmentedButtonthis this pointer for chaining
setSelectedKey(sKey): sap.m.SegmentedButton
Sets the selectedKey and is usable only when the control is initiated with the items aggregation.
Parameters:
stringsKeyThe key of the button to be selected
Returns:
sap.m.SegmentedButtonthis pointer for chaining
Since:
1.28
setWidth(sWidth): sap.m.SegmentedButton

Sets a new value for property width.

Defines the width of the SegmentedButton control. If not set, it uses the minimum required width to make all buttons inside of the same size (based on the biggest button).

When called with a value of null or undefined, the default value of the property will be restored.

Parameters:
sap.ui.core.CSSSizesWidthNew value for property width
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
unbindItems(): sap.m.SegmentedButton
Unbinds aggregation items from model data.
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
Since:
1.28
unbindSelectedKey(): sap.m.SegmentedButton
Unbinds property selectedKey from model data.
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
Since:
1.28.0
addButton(oButton): sap.m.SegmentedButton
Adds some button to the aggregation buttons.
Parameters:
sap.m.ButtonoButtonthe button to add; if empty, nothing is inserted
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
Deprecated API:
Since 1.28.0 Instead use the "items" aggregation.
destroyButtons(): sap.m.SegmentedButton
Destroys all the buttons in the aggregation buttons.
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
Deprecated API:
Since 1.28.0 Instead use the "items" aggregation.
getButtons(): sap.m.Button[]

Gets content of aggregation buttons.

The buttons of the SegmentedButton control. The items set in this aggregation are used as an interface for the buttons displayed by the control. Only the properties ID, icon, text, enabled and textDirections of the Button control are evaluated. Setting other properties of the button will have no effect. Alternatively, you can use the createButton method to add buttons.

Returns:
sap.m.Button[]
Deprecated API:
Since 1.28.0 Instead use the "items" aggregation.
indexOfButton(oButton): int
Checks for the provided sap.m.Button in the aggregation buttons. and returns its index if found or -1 otherwise.
Parameters:
sap.m.ButtonoButtonThe button whose index is looked for
Returns:
intThe index of the provided control in the aggregation if found, or -1 otherwise
Deprecated API:
Since 1.28.0 Instead use the "items" aggregation.
insertButton(oButton, iIndex): sap.m.SegmentedButton
Inserts a button into the aggregation buttons.
Parameters:
sap.m.ButtonoButtonthe button to insert; if empty, nothing is inserted
intiIndexthe 0-based index the button should be inserted at; for a negative value of iIndex, the button is inserted at position 0; for a value greater than the current size of the aggregation, the button is inserted at the last position
Returns:
sap.m.SegmentedButtonReference to this in order to allow method chaining
Deprecated API:
Since 1.28.0 Instead use the "items" aggregation.
removeAllButtons(): sap.m.Button[]

Removes all the controls from the aggregation buttons.

Additionally, it unregisters them from the hosting UIArea.

Returns:
sap.m.Button[]An array of the removed elements (might be empty)
Deprecated API:
Since 1.28.0 Instead use the "items" aggregation.
removeButton(vButton): sap.m.Button
Removes a button from the aggregation buttons.
Parameters:
int|string|sap.m.ButtonvButtonThe button to remove or its index or id
Returns:
sap.m.ButtonThe removed button or null
Deprecated API:
Since 1.28.0 Instead use the "items" aggregation.