Skip to content

You are here: Creating a CollectionView Using a Constructor: voltmx.ui.CollectionView

CollectionView Widget

A CollectionView consists of multiple items, and each item can have multiple child widgets. The CollectionView widget is similar to the SegmentedUI widget, and shares many of that widgets properties and methods. The items that fill the CollectionView widget are based on templates.

CollectionView widget can be created only through code.

Following are the real-time use cases of CollectionView widget:

  • Group Data: Group data into rows and columns using CollectionView widgets.
  • Data Handling: Displays data from various services in your application by using CollectionView widgets. For example, if you have a service that contains the data of various luxury cars, its images, and prices, you can display it in your application using CollectionView widget.
  • Define Templates: Create templates to define reusable structure for CollectionView widgets. Templates help you to attain a consistent look-and-feel for the rows and sections of a CollectionView widget.

Widgets are normally added to your application using Volt MX Iris, but can also be added from code. For general information on using widgets in Volt MX Iris, see Designing an Application in the Iris User Guide.

For a more hands-on approach on how you can implement CollectionView widget, import and preview the File Gallery sample app by using Volt MX Iris.

The CollectionView widget capabilities can be broadly categorized into the following:

Layout

Properties Description
centerX Determines the center of a widget measured from the left bounds of the parent container.
centerY Determines the center of a widget measured from the top bounds of the parent container.
contentOffset Returns the current coordinates of the top left corner of the scrollable region in the item.
contentOffsetMeasured Returns the current coordinates of the top left corner of the scrollable region in the item.
contentSize Specifies the size of the scrollable area in the widget. Collection view items will appear in this area.
itemTemplate Indicates the common template to be used for each item while creating the item and filling the data.
layout Determines how the items get arranged within the CollectionView widget.
maxHeight Specifies the maximum height of the widget and is applicable only when the height property is not specified.
maxWidth Specifies the maximum width of the widget and is applicable only when the width property is not specified.
minHeight Specifies the minimum height of the widget and is applicable only when the height property is not specified.
minWidth Specifies the minimum width of the widget and is applicable only when the width property is not specified.
right Determines the lower right corner of the widget and is measured from the right bounds of the parent container.
top Determines the top edge of the widget and measured from the top bounds of the parent container.
width Determines the width of the widget and is measured along the x-axis.
zIndex Specifies the stack order of a widget.

UI Appearance

Properties Description
itemSelectedSkin Specifies the skin that must be applied when user selects the item.
itemSkin The default skin for each item.
pressedSkin Specifies the skin to indicate that an item of the collection is pressed or clicked.
minItemSpace Specifies the minimum spacing between items.
minLineSpace Specifies the minimum spacing between lines of items.
opacity Specifies the opacity of the widget.
pullToRefreshView Displays a Flex Container above the content area of the CollectionView widget when the widget is pulled down from the top.
pushToRefreshView Displays a Flex Container below the content area of the CollectionView widget when the widget is pushed up from the bottom.
releaseToPullRefreshView Displays a Flex Container above the content area of the CollectionView widget when the widget is pulled down from the top and then released.
releaseToPushRefreshView Displays a Flex Container below the content area of the CollectionView widget when the widget is pushed up from the bottom and released.
retainSelection Specifies if the segment should retain the selection made even when the user navigates out and back to the form.
sectionFooterSkin Specifies the skin to be applied to the Section footer.
sectionHeaderSkin Specifies the skin to be applied to the Section Header.
sectionFooterTemplate Specifies the template to use for each section when creating the section footer and filling the data.
sectionHeaderTemplate Specifies the common template to be used for each section when creating the section header and filling the data.
skin Specifies the skin to be applied to the entire CollectionView.
Events Description
onItemDisplay Triggered when you display any item in the CollectionView widget.
onItemSelect Triggered when the user selects any item in the CollectionView.

Scrolling Functionalities

Methods Description
scrollToItemAtIndex Scrolls the collection view so that the item at given index comes into the view port.
Properties Description
reachingBeginningOffset Specifies an offset from the top of the content area of the CollectionView widget.
reachingEndOffset Specifies an offset from the bottom of the content area of the CollectionView widget.
scrollDirection Specifies the direction in which the widget should scroll.
scrollsToTop Enables you to scroll the view to the top by tapping a device’s status bar.
showScrollbars Specifies if the scrollbars are visible all the time.
Events Description
onDecelerationStarted Triggered only on iOS. It is called when deceleration starts at the end of scrolling.
onPull Invoked by the platform when scrolling the CollectionView widget from it's edges.
onPush Invoked by the platform when scrolling the CollectionView widget widget from it's edges.
onReachingBegining Called when scrolling reaches the beginning of the CollectionView widget.
onReachingEnd Called when scrolling reaches the end of the CollectionView widget.
onScrollStart Indicates that the scroll container inside the CollectionView widget started scrolling.
onScrollTouchReleased Indicates that user scrolling touch on the display is released. This callback is called asynchronously.
onScrolling Indicates that segment scrolling is in progress. This callback is called asynchronously.
onScrollEnd Indicates that segment scrolling has come to an end.
onScrollWidgetPosition Invoked by the platform when the widget location position gets changed on scrolling.

Data Management

Properties Description
data Specifies the set of values for each item.
Methods Description
addAll Allows you to add new items to the collection.
addSectionAt Allows you to add one section with items to the collection.
removeAll Removes all the widget on the container.
removeAt Removes a widget at the given index from the Form container.
removeSectionAt Allows you to remove a section at the given index within a collection.

3D Touch

Methods Description
registerForPeekandPop Registers a widget to enable 3D Touch peek and pop gestures.
setOnPeek Sets and overrides the existing onPeekCallback for the widget.
setOnPop Overrides the existing onPopCallback for the widget.
unregisterForPeekandPop Unregisters a widget from 3D Touch peek and pop gestures.

User Input Handling

Methods Description
addGestureRecognizer Allows you to set a gesture recognizer for a specified gesture for a specified widget.
removeGestureRecognizer Allows you to remove the specified gesture recognizer for the specified widget.

Enabling RTL

Properties Description
retainContentAlignment Helps to retain the content alignment of the widget while applying RTL.
retainFlexPositionProperties Helps to retain the left, right and padding properties while applying RTL.
retainFlowHorizontalAlignment Enables you to change the horizontal flow of the widget from left to right.

Miscellaneous

Methods Description
getBadge Enables you to read the badge value (if any) attached to the specified widget.
setBadge Enables you to set the badge value to the given widget at the upper, right corner of the widget.
Properties Description
cursorType Specifies the type of the mouse pointer used.
isMaster Specifies whether the container is a master container.
widgetSwipeMove Used to enable and configure the left or right swipe actions for a widget.

Configurations common to all widgets

Methods Description
convertPointFromWidget Allows you to convert the coordinate system from a widget to a point (receiver's coordinate system).
convertPointToWidget Allows you to convert the receiver's co-ordinate system from a point to a Widget.
removeFromParent Allows you to remove a child widget from a parent widget.
setEnabled Specifies the widget that must be enabled or disabled.
setFocus Specifies the widget on which there must be focus.
setVisibility Use this method to set the visibility of the widget.
Properties Description
accessibilityConfig Enables you to control accessibility behavior and alternative text for the widget.
enable Allows you to make a widget visible but not actionable.
enableCache Enables you to improve the performance of Positional Dimension Animations.
id A unique identifier of Segment consisting of alpha numeric characters.
info A custom JSObject with the key value pairs that a developer can use to store the context with the widget.
isVisible Controls the visibility of a widget on the form.
parent Gives you the ability to access the parent of the widget.

CollectionView Widget Basics

A CollectionView item can contain any of the following widgets:

The data returned when selectedItem is called on the CollectionView widget when the item has the following widgets:

Widget Name Properties Description
CheckBoxGroup selectedKeys, selectedKeyValues An array of key value pairs with the keys as mentioned.
RadioButtonGroup selectedKey, selectedKeyValue  
ComboBox selectedKey, selectedKeyValue  
TextBox text  
TextArea text  
Calendar dataComponents An array of the date components

Each of the above widgets is allowed to have its own skin and control. This gives the flexibility to design a collection view with separate interconnected widgets and expose their properties for mapping.

When a CollectionView template is created based on the input data, the template is repeated in the Collection.

Creating a CollectionView Using a Constructor: voltmx.ui.CollectionView


var collection = new voltmx.ui.CollectionView (basicConf, layoutConf, pspConf);
  • basicConf is an object with basic properties.
  • layoutConf is an object with layout properties.
  • pspConf is an object with platform specific properties.

Note: The configuration properties should be passed only in t