Licensed to the Apache Software Foundation (ASF) under one or more

contributor license agreements. See the NOTICE file distributed with

this work for additional information regarding copyright ownership.

The ASF licenses this file to You under the Apache License, Version 2.0

(the “License”); you may not use this file except in compliance with

the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software

distributed under the License is distributed on an “AS IS” BASIS,

WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

See the License for the specific language governing permissions and

limitations under the License.

layout: docpage title: Jewel List description: The Jewel List permalink: /component-sets/jewel/list

< Jewel Components list

Jewel List

Available since version 0.9.4.

ClassExtendsImplements
org.apache.royale.jewel.List{:target=‘_blank’}org.apache.royale.jewel.DataContainer{:target=‘_blank’}IVariableRowHeight{:target=‘_blank’}

Note: This component is currently only available for JavaScript.

Overview

The List class is a DataContainer component that provides item selection and keyboard navigation through items (check DataContainer for more info about core List functionality). If you just need to show a list of items you can use a DataContainer; if you need interaction with items, use List.

List default item renderer is ListItemRenderer{:target=‘_blank’}. When there's a need of any advanced item, we recommend using layout to extend ListItemRenderer to create a custom renderer. List can also use factories and data mappers for renderers that suport selection.

This component supports scrolling by default and gives you control over rollover and row height for each cell in every column. You can also programatically scroll to any item by index.

Example of use

In MXML declare a List like this:

<j:List width="100%" height="250">
    <js:ArrayList localId="avengers" source="[Iron Man, Hulk, Thor, Captain America, Black Widow, Hawkeye]"/>
</j:List>

We can nest the ArrayList directly into the DataContainer tag because “dataProvider” is its DefaultProperty.

In ActionScript we can do the same in the following way:

var list:List = new List();
list.dataProvider = new ArrayList(["Iron Man", "Hulk", "Thor", "Captain America", "Black Widow", "Hawkeye"]);
// add the List to the parent
parent.addElement(list);

where parent is the container where the control will be added.

Relevant Properties and Methods

Check the Reference of org.apache.royale.jewel.List{:target=‘_blank’} for a more detailed list of properties and methods.

Properties

PROPERTYTypeDescription
currentStateStringThe name of the current state.
itemRendererStringThe class or factory used to display each item.
labelFieldStringThe name of field within the data used for display.
dataProviderObjectThe data being display by the List. Is the DefaultProperty. In Jewel an ArrayList{:target=‘_blank’}
numElementsintThe number of element children that can be laid out.
rollOverIndexintThe index of the item currently below the pointer.
selectedIndexintThe index of the currently selected item.
selectedItemObjectThe item currently selected.
statesArrayThe array of view states. These should be instances of org.apache.royale.states.State{:target=‘_blank’}
strandChildrenIParent{:target=‘_blank’}An object to access the immediate children of the strand.

Methods

MethodParametersDescription
addElementc(IChild), dispatchEvent(Boolean=true)Add a component to the parent.
addElementAtc(IChild), index(int), dispatchEvent(Boolean=true)Add a component to the parent at the specified index.
getElementIndexc(IChild)Gets the index of this subcomponent.
getElementAtindex(int)Get a component from the parent at specified index.
removeElementc(IChild), dispatchEvent(Boolean=true)Remove a component from the parent.
scrollToIndexindex(int)Ensures that the data provider item at the given index is visible.

Relevant Events

The most important event is change, which is dispatched whenever the list's selected item changes.

You can attach callback listeners to the change event in MXML as follows:

<j:List change="changeHandler(event)"/>

the change event will use the changeHandler callback function you provide in ActionScript:

<fx:Script>
    <![CDATA[      
        private function changeHandler(event:Event):void {
            trace("[Selection] index", event.target.selectedIndex, "item", event.target.selectedItem);
        }
    ]]>
</fx:Script>

When the user selects any item a change event is dispatched and a message appears in the console log showing the “index” and the “item” that correspond to the selection.

When a programmatic change event is needed you can use the selectionChanged event instead to listen for selection changes.

In ActionScript we can add an event handler this way:

var list:List = new List();
list.addEventListener(Event.CHANGE, changeHandler);
parent.addElement(list);

Relevant Beads

Bead TypeImplementationDescription
ArrayListSelectionModel{:target=‘_blank’}IBeadModel{:target=‘_blank’}This is the default model bead.
ListSingleSelectionMouseController{:target=‘_blank’}IBeadController{:target=‘_blank’}This is the default controller for input and output.
ListView{:target=‘_blank’}IBeadView{:target=‘_blank’}This is the default view bead.
VerticalLayout{:target=‘_blank’}IBeadLayout{:target=‘_blank’}This is the default layout bead.
SelectionDataItemRendererFactoryForCollectionView{:target=‘_blank’}IDataProviderItemRendererMapper{:target=‘_blank’}Map data to itemrenders.
SelectableItemRendererClassFactory{:target=‘_blank’}IItemRendererClassFactory{:target=‘_blank’}The factory of itemrenders.
ListItemRenderer{:target=‘_blank’}IItemRenderer{:target=‘_blank’}The itemrenders class to instantiate.
ListItemRendererInitializer{:target=‘_blank’}IItemRendererInitializer{:target=‘_blank’}Configuration of itemrenders to instantiate.
ScrollingViewport{:target=‘_blank’}IViewport{:target=‘_blank’}Define the area that display content.

Optional Beads

Bead TypeImplementationDescription
HorizontalListScroll{:target=‘_blank’}org.apache.royale.core.IBead{:target=‘_blank’}Provide horizontal scroll to the list.
ListAlternateRowColor{:target=‘_blank’}org.apache.royale.core.IBead{:target=‘_blank’}Provide alternate background color of every row with two colors.
ListPresentationModel{:target=‘_blank’}EventDispatcher{:target=‘_blank’}(IListPresentationModel{:target=‘_blank’})Provide values used to present visuals.

Common Beads

Jewel List can use any of the layout beads available in Jewel library. Also you can check Related controls section to see some advanced or preconfigured data containers.

More examples

Related controls

Other useful Jewel containers components are: