Package | mx.collections |
Class | public class ListCollectionView |
Inheritance | ListCollectionView flash.utils.Proxy |
Implements | ICollectionView, IList, IMXMLObject |
Subclasses | ArrayCollection, XMLListCollection |
ICollectionView
interface to an object that conforms to the
IList
interface. As a result, you can pass an object of this class
to anything that requires an IList
or ICollectionView
.
This class also lets you use [ ] array notation
to access the getItemAt()
and setItemAt()
methods.
If you use code such as myListCollectionView[index]
Flex calls the myListCollectionView
object's
getItemAt()
or setItemAt()
method.
The <mx:ListCollectionView>
has the following attributes,
which all of its subclasses inherit:
<mx:ListCollectionView Properties filterFunction="null" list="null" sort="null" Events collectionChange="No default" />
Property | Defined by | ||
---|---|---|---|
filterFunction : Function
A function that the view will use to eliminate items that do not
match the function's criteria.
| ListCollectionView | ||
length : int [read-only]
The number of items in this collection.
| ListCollectionView | ||
list : IList
The IList that this collection view wraps.
| ListCollectionView | ||
sort : Sort
The Sort that will be applied to the ICollectionView.
| ListCollectionView |
Property | Defined by | ||
---|---|---|---|
localIndex : Array
When the view is sorted or filtered the
localIndex property
contains an array of items in the sorted or filtered (ordered, reduced)
view, in the sorted order. | ListCollectionView |
Method | Defined by | ||
---|---|---|---|
ListCollectionView(list:IList = null)
The ListCollectionView constructor.
| ListCollectionView | ||
addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
| ListCollectionView | ||
addItem(item:Object):void
Adds the specified item to the end of the list.
| ListCollectionView | ||
addItemAt(item:Object, index:int):void
Adds the item at the specified index.
| ListCollectionView | ||
contains(item:Object):Boolean
Returns whether the view contains the specified object.
| ListCollectionView | ||
Creates a new IViewCursor that works with this view.
| ListCollectionView | ||
disableAutoUpdate():void
Prevents changes to the collection itself and items within the
collection from being dispatched by the view.
| ListCollectionView | ||
dispatchEvent(event:Event):Boolean
| ListCollectionView | ||
enableAutoUpdate():void
Enables auto-updating.
| ListCollectionView | ||
getItemAt(index:int, prefetch:int = 0):Object
Gets the item at the specified index.
| ListCollectionView | ||
getItemIndex(item:Object):int
Returns the index of the item if it is in the list such that
getItemAt(index) == item.
| ListCollectionView | ||
hasEventListener(type:String):Boolean
| ListCollectionView | ||
initialized(document:Object, id:String):void
Called automatically by the MXML compiler when the ListCollectionView
is created using an MXML tag.
| ListCollectionView | ||
itemUpdated(item:Object, property:Object = null, oldValue:Object = null, newValue:Object = null):void
Notifies the view that an item has been updated.
| ListCollectionView | ||
refresh():Boolean
Applies the sort and filter to the view.
| ListCollectionView | ||
removeAll():void
Remove all items from the list.
| ListCollectionView | ||
removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
| ListCollectionView | ||
removeItemAt(index:int):Object
Removes the item at the specified index and returns it.
| ListCollectionView | ||
setItemAt(item:Object, index:int):Object
Places the item at the specified index.
| ListCollectionView | ||
toArray():Array
Returns an Array that is populated in the same order as the IList
implementation.
| ListCollectionView | ||
toString():String
Prints the contents of this view to a string and returns it.
| ListCollectionView | ||
willTrigger(type:String):Boolean
| ListCollectionView |
Event | Summary | Defined by | ||
---|---|---|---|---|
Dispatched when the ICollectionView has been updated in some way. | ListCollectionView |
filterFunction | property |
filterFunction:Function
[read-write]A function that the view will use to eliminate items that do not match the function's criteria. A filterFunction is expected to have the following signature:
f(item:Object):Booleanwhere the return value is
true
if the specified item
should remain in the view.
If a filter is unsupported, Flex throws an error when accessing
this property.
You must call refresh()
after setting the
filterFunction
property for the view to update.
Note: The Flex implementations of ICollectionView retrieve all items from a remote location before executing the filter function. If you use paging, apply the filter to the remote collection before you retrieve the data.
This property can be used as the source for data binding.
Implementation public function get filterFunction():Function
public function set filterFunction(value:Function):void
See also
length | property |
length:int
[read-only]The number of items in this collection. 0 means no items while -1 means the length is unknown.
This property can be used as the source for data binding.
Implementation public function get length():int
list | property |
list:IList
[read-write]The IList that this collection view wraps.
This property can be used as the source for data binding.
Implementation public function get list():IList
public function set list(value:IList):void
localIndex | property |
protected var localIndex:Array
When the view is sorted or filtered the localIndex
property
contains an array of items in the sorted or filtered (ordered, reduced)
view, in the sorted order.
The ListCollectionView class uses this property to access the items in
the view.
The localIndex
property should never contain anything
that is not in the source, but may not have everything in the source.
This property is null
when there is no sort.
sort | property |
sort:Sort
[read-write]
The Sort that will be applied to the ICollectionView.
Setting the sort does not automatically refresh the view,
so you must call the refresh()
method
after setting this property.
If sort is unsupported an error will be thrown when accessing
this property.
Note: The Flex implementations of ICollectionView retrieve all items from a remote location before executing a sort. If you use paging with a sorted list, apply the sort to the remote collection before you retrieve the data.
This property can be used as the source for data binding.
Implementation public function get sort():Sort
public function set sort(value:Sort):void
See also
ListCollectionView | () | constructor |
public function ListCollectionView(list:IList = null)
The ListCollectionView constructor.
Parameterslist:IList (default = null ) — the IList this ListCollectionView is meant to wrap.
|
addEventListener | () | method |
public function addEventListener(type:String, listener:Function, useCapture:Boolean = false, priority:int = 0, useWeakReference:Boolean = false):void
Parameters
type:String |
|
listener:Function |
|
useCapture:Boolean (default = false )
|
|
priority:int (default = 0 )
|
|
useWeakReference:Boolean (default = false )
|
addItem | () | method |
public function addItem(item:Object):void
Adds the specified item to the end of the list.
Equivalent to addItemAt(item, length)
.
item:Object — The item to add.
|
addItemAt | () | method |
public function addItemAt(item:Object, index:int):void
Adds the item at the specified index. The index of any item greater than the index of the added item is increased by one. If the the specified index is less than zero or greater than the length of the list, a RangeError is thrown.
Parametersitem:Object — The item to place at the index.
|
|
index:int — The index at which to place the item.
|
contains | () | method |
public function contains(item:Object):Boolean
Returns whether the view contains the specified object.
Unlike the IViewCursor.findxxx
methods,
this search is succesful only if it finds an item that exactly
matches the parameter.
If the view has a filter applied to it this method may return
false
even if the underlying collection
does contain the item.
item:Object — The object to look for.
|
Boolean — true if the ICollectionView, after applying any filter,
contains the item; false otherwise.
|
See also
createCursor | () | method |
public function createCursor():IViewCursor
Creates a new IViewCursor that works with this view.
ReturnsIViewCursor —
A new IViewCursor implementation.
|
disableAutoUpdate | () | method |
public function disableAutoUpdate():void
Prevents changes to the collection itself and items within the
collection from being dispatched by the view.
Also prevents the view from updating the positions of items
if the positions change in the collection.
The changes will be queued and dispatched appropriately
after enableAutoUpdate
is called.
If more events than updates to a single item occur,
the view may end up resetting.
The disableAutoUpdate
method acts cumulatively;
the same number of calls to enableAutoUpdate
are required for the view to dispatch events and refresh.
Note that disableAutoUpdate
only affects the
individual view; edits may be detected on an individual
basis by other views.
See also
dispatchEvent | () | method |
public function dispatchEvent(event:Event):Boolean
Parameters
event:Event |
Boolean |
enableAutoUpdate | () | method |
public function enableAutoUpdate():void
Enables auto-updating.
See disableAutoUpdate
for more information.
See also
getItemAt | () | method |
public function getItemAt(index:int, prefetch:int = 0):Object
Gets the item at the specified index.
Parametersindex:int — The index in the list from which to retrieve the item.
|
|
prefetch:int (default = 0 ) — An int indicating both the direction
and number of items to fetch during the request if the item is
not local.
|
Object — The item at that index, or null if there is none.
|
getItemIndex | () | method |
public function getItemIndex(item:Object):int
Returns the index of the item if it is in the list such that getItemAt(index) == item.
Note: unlike IViewCursor.findxxx()
methods,
The getItemIndex()
method cannot take a parameter with
only a subset of the fields in the item being serched for;
this method always searches for an item that exactly matches
the input parameter.
item:Object — The item to find.
|
int — The index of the item, or -1 if the item is not in the list.
|
hasEventListener | () | method |
public function hasEventListener(type:String):Boolean
Parameters
type:String |
Boolean |
initialized | () | method |
public function initialized(document:Object, id:String):void
Called automatically by the MXML compiler when the ListCollectionView
is created using an MXML tag.
If you create the ListCollectionView through ActionScript, you
must call this method passing in the MXML document and
null
for the id
.
document:Object — The MXML document containing this ListCollectionView.
|
|
id:String — Ignored.
|
itemUpdated | () | method |
public function itemUpdated(item:Object, property:Object = null, oldValue:Object = null, newValue:Object = null):void
Notifies the view that an item has been updated.
This is useful if the contents of the view do not implement
IEventDispatcher
and dispatches a
PropertyChangeEvent
.
If a property is specified the view may be able to optimize its
notification mechanism.
Otherwise it may choose to simply refresh the whole view.
item:Object — The item within the view that was updated.
|
|
property:Object (default = null ) — The name of the property that was updated.
|
|
oldValue:Object (default = null ) — The old value of that property. (If property was null,
this can be the old value of the item.)
|
|
newValue:Object (default = null ) — The new value of that property. (If property was null,
there's no need to specify this as the item is assumed to be
the new value.)
|
See also
refresh | () | method |
public function refresh():Boolean
Applies the sort and filter to the view.
The ICollectionView does not detect changes to a sort or
filter automatically, so you must call the refresh()
method to update the view after setting the sort
or filterFunction
property.
If your ICollectionView implementation also implements
the IMXMLObject interface, you should to call the
refresh()
method from your initialized()
method.
Returns true
if the refresh was successful
and false
if the sort is not yet complete
(e.g., items are still pending).
A client of the view should wait for a CollectionEvent event
with the CollectionEventKind.REFRESH
kind
property to ensure that the refresh()
operation is
complete.
Boolean — true if the refresh() was complete,
false if the refresh() is incomplete.
|
removeAll | () | method |
public function removeAll():void
Remove all items from the list.
removeEventListener | () | method |
public function removeEventListener(type:String, listener:Function, useCapture:Boolean = false):void
Parameters
type:String |
|
listener:Function |
|
useCapture:Boolean (default = false )
|
removeItemAt | () | method |
public function removeItemAt(index:int):Object
Removes the item at the specified index and returns it. Any items that were after this index are now one index earlier.
Parametersindex:int — The index from which to remove the item.
|
Object — The item that was removed.
|
setItemAt | () | method |
public function setItemAt(item:Object, index:int):Object
Places the item at the specified index. If an item was already at that index the new item will replace it and it will be returned.
Parametersitem:Object — The new item to be placed at the specified index.
|
|
index:int — The index at which to place the item.
|
Object — The item that was replaced, or null if none.
|
toArray | () | method |
public function toArray():Array
Returns an Array that is populated in the same order as the IList implementation. This method can throw an ItemPendingError.
ReturnsArray — The array.
|
toString | () | method |
public function toString():String
Prints the contents of this view to a string and returns it.
ReturnsString — The contents of this view, in string form.
|
willTrigger | () | method |
public function willTrigger(type:String):Boolean
Parameters
type:String |
Boolean |
collectionChange | event |
mx.events.CollectionEvent
mx.events.CollectionEvent.COLLECTION_CHANGE
Dispatched when the ICollectionView has been updated in some way.
The CollectionEvent.COLLECTION_CHANGE constant defines the value of the
type
property of the event object for an event that is
dispatched when a collection has changed.
The properties of the event object have the following values. Not all properties are meaningful for all kinds of events. See the detailed property descriptions for more information.
Property | Value |
---|---|
bubbles | false |
cancelable | false |
currentTarget | The Object that defines the
event listener that handles the event. For example, if you use
myButton.addEventListener() to register an event listener,
myButton is the value of the currentTarget . |
items | An Array of objects with
information about the items affected by the event.
The contents of this field depend on the event kind;
for details see the items property |
kind | The kind of event. The valid values are defined in the CollectionEventKind class as constants. |
location | Location within the target collection
of the item(s) specified in the items property. |
oldLocation | the previous location in the collection
of the item specified in the items property. |
target | The Object that dispatched the event;
it is not always the Object listening for the event.
Use the currentTarget property to always access the
Object listening for the event. |
type | CollectionEvent.COLLECTION_CHANGE |