Packageqnx.ui.data
Classpublic class DataProvider
InheritanceDataProvider Inheritance flash.events.EventDispatcher
Implements IDataProvider
Subclasses SectionDataProvider

The DataProvider class provides a linear representation of a set of data and methods that enable you to modify the data. List classes, such as the List and TileList use the DataProvider class in order to handle their data.

See also

SectionDataProvider
List
TileList
RoundList
ScrollPane


Public Properties
 PropertyDefined By
  data : Array
[read-only] Returns the Array of item data.
DataProvider
  length : int
[read-only] Returns the length of the data.
DataProvider
Public Methods
 MethodDefined By
  
DataProvider(dp:Array = null, dispatchCreate:Boolean = false)
Creates a new DataProvider instance.
DataProvider
  
addItem(item:Object):void
Adds an item to the DataProvider.
DataProvider
  
addItemAt(item:Object, index:int):void
Adds an item at the specified index.
DataProvider
  
addItemsAt(items:Array, index:int):void
Adds an array item at the specified index.
DataProvider
  
Creates a clone of this DataProvider.
DataProvider
  
getItemAt(index:int):Object
Returns the item at a given offset.
DataProvider
  
indexOf(item:Object):int
Returns the index of a given object.
DataProvider
  
removeAll():void
Removes all items from the DataProvider instance.
DataProvider
  
removeItem(item:Object):void
Removes the item from the DataProvider instance.
DataProvider
  
removeItemAt(index:int):void
Removes an item from the DataProvider at a given offset.
DataProvider
  
replaceItem(item:Object, oldObject:Object):void
Replaces an item, given the new item object and the item to replace.
DataProvider
  
replaceItemAt(item:Object, index:int):void
Replaces the item at a given offset.
DataProvider
  
setItems(arr:Array, throwEvent:Boolean = false):void
Sets the entire data provider to the new array.
DataProvider
  
updateItem(item:Object, oldObject:Object):void
Updates an item, given the new item data object and the item to update.
DataProvider
  
updateItemAt(item:Object, index:int):void
Updates the item at a given offset.
DataProvider
  
updateItemsAt(items:Array, index:int):void
Updates the items starting at the specified index with new items.
DataProvider
Events
 Event Summary Defined By
   Dispatched when the DataProvider is modified.DataProvider
Property Detail
dataproperty
data:Array  [read-only]

Returns the Array of item data.


Implementation
    public function get data():Array
lengthproperty 
length:int  [read-only]

Returns the length of the data.


Implementation
    public function get length():int
Constructor Detail
DataProvider()Constructor
public function DataProvider(dp:Array = null, dispatchCreate:Boolean = false)

Creates a new DataProvider instance.

Parameters
dp:Array (default = null) — An Array containing the initial set of items.
 
dispatchCreate:Boolean (default = false) — Setting this value to true causes a DataProviderEvent.UPDATE_ALL event to occur on creation. This parameter is set to false by default.
Method Detail
addItem()method
public function addItem(item:Object):void

Adds an item to the DataProvider. The item is added to the end of the DataProvider.

In the following example, a new object is created and added to a List. The object is instantiated, and the label property is set. By default, the List object uses the label property of each item to render the item labels in the List.

         var myObj:Object = new Object();
         myObj.label = "Bread";
         
         myList.addItem(myObj);
         

Parameters

item:Object — The item object to add.

addItemAt()method 
public function addItemAt(item:Object, index:int):void

Adds an item at the specified index.

The following listing adds an object with the label "December" to the fifth index position of the DataProvider.

        myDP.addItemAt({label: "December"}, 5);
        

Parameters

item:Object — The item object to add.
 
index:int — The index, or offset, at which to add the item.

addItemsAt()method 
public function addItemsAt(items:Array, index:int):void

Adds an array item at the specified index.

In the following listing, an Array is created and added to a List at the third index position.

        var myArr:Array = new Array();
        myArr.push({label: "Juice"}, {label: "Tooth paste"}, {label: "Soap"});
        
        myList.addItemsAt(myArr, 3);
        

Parameters

items:Array — The array of items to add.
 
index:int — The index, or offset, at which to add the items.

clone()method 
public function clone():IDataProvider

Creates a clone of this DataProvider. The new instance contains the same data.

Returns
IDataProvider — The cloned DataProvider.
getItemAt()method 
public function getItemAt(index:int):Object

Returns the item at a given offset.

Parameters

index:int — The offset of the item to return.

Returns
Object — The item object.
indexOf()method 
public function indexOf(item:Object):int

Returns the index of a given object.

Parameters

item:Object — The object for which to return the index.

Returns
int — The index of the object. Returns -1 if the item is not found in the DataProvider.
removeAll()method 
public function removeAll():void

Removes all items from the DataProvider instance.

removeItem()method 
public function removeItem(item:Object):void

Removes the item from the DataProvider instance.

Parameters

item:Object — The item to remove.

removeItemAt()method 
public function removeItemAt(index:int):void

Removes an item from the DataProvider at a given offset.

The following example removes the first item in the DataProvider.

         myList.removeItemAt(0);
         

Parameters

index:int — The offset of the item to remove.

replaceItem()method 
public function replaceItem(item:Object, oldObject:Object):void

Replaces an item, given the new item object and the item to replace.

Parameters

item:Object — The new item object data.
 
oldObject:Object — The item to replace.

replaceItemAt()method 
public function replaceItemAt(item:Object, index:int):void

Replaces the item at a given offset.

In the following example, the first item in the DataProvider is replaced with a new item.

         myList.replaceItemAt(myObj, 0);
         

Parameters

item:Object — The new item object.
 
index:int — The offset of the item to replace.

setItems()method 
public function setItems(arr:Array, throwEvent:Boolean = false):void

Sets the entire data provider to the new array.

The following listing creates an array of objects and applies the array to the DataProvider using the setItems() method.

        var arrMonth:Array=[];
        arrMonth.push({label: "January"});
        arrMonth.push({label: "February"});
        arrMonth.push({label: "March"});
        arrMonth.push({label: "April"});
        arrMonth.push({label: "May"});
        arrMonth.push({label: "June"});
        arrMonth.push({label: "July"});
        arrMonth.push({label: "August"});
        arrMonth.push({label: "September"});
        arrMonth.push({label: "October"});
        arrMonth.push({label: "November"});
        arrMonth.push({label: "December"});
        
        var myDP:DataProvider = new DataProvider();
        myDP.setItems(arrMonth);
        

Parameters

arr:Array — An Array of new values.
 
throwEvent:Boolean (default = false) — When set to true, a DataProviderEvent.UPDATE_ALL event is fired. The default is false.

updateItem()method 
public function updateItem(item:Object, oldObject:Object):void

Updates an item, given the new item data object and the item to update.

Parameters

item:Object — The new item.
 
oldObject:Object — The item to update.

updateItemAt()method 
public function updateItemAt(item:Object, index:int):void

Updates the item at a given offset.

Parameters

item:Object — The new item object data.
 
index:int — The offset at which to update the item.

updateItemsAt()method 
public function updateItemsAt(items:Array, index:int):void

Updates the items starting at the specified index with new items.

Parameters

items:Array — The new items to be updated.
 
index:int — The start index to update the items

Event Detail
dataChange Event
Event Object Type: qnx.ui.events.DataProviderEvent
DataProviderEvent.type property = qnx.ui.events.DataProviderEvent.DATA_CHANGE

Dispatched when the DataProvider is modified.