Main Page | Packages | Class Tree | Index | Help

xp.data

class ListDataSource

Object
  |
  +--xp.system.DispatcherObject
        |
        +--xp.data.ItemDataSource
              |
              +--xp.data.DataSource
                    |
                    +--xp.data.ListDataSource

All Known Subclasses: ObjectDataSource, XMLDataSource

class ListDataSource
extends DataSource

A building block for creating data-driven applications.

A ListDataSource is a linear collection (like an array) of items.
Each item is an object composed of many fields of data.
A ListDataSource expose 2 interfaces;
The IDataSource interface which expose the current item through the data property
The IList interface wheich exposes the collection of data items.
The currentItem can be changed by moving the selectedIndex of the IList interface.
You can access any item by index (as you can with an array), using getItemAt() on the IList interface.

Event summary for the ListDataSource class
The following table lists events of the ListDataSource class.











EventTypeDescription
xp.events.ModelChangedEventmodeChangedBroadcast when the data model changes.
xp.events.EventloadBroadcast after the list has loaded.
xp.events.EventinsertItemBroadcast before inserting the current item.
xp.events.EventupdateItemBroadcast before editing the current item.
xp.events.EventdeleteItemBroadcast before deleting the current item.
xp.events.EventapplyChangesBroadcast before row item changes are applied. You can accept, amend or reject the changes in you own validation routines
xp.events.EventaddItemBroadcast before an item is added.
xp.events.EventremoveItemBroadcast before an item is removed.
xp.events.ItemEventnewItemBroadcast when a new item is created.
xp.events.ItemEventcalcFieldsBroadcast when the calculated fields need refreshing.
xp.events.EventselectBroadcast when selectedIndex changes.


Author:
ProWin Computers Ltd. - Rob Edgar

Version:
3.0.0.000

See also:


Field Summary

public
canSort: Boolean
Does this list support sorting

public static
classInfo: Object
A static class information object

public
selectFirstOnLoad: Boolean
Controls whether the first record in the dataSource is selected when the list loads

Fields inherited from class xp.data.DataSource

autoCommit, autoEdit, autoInsert, calcFields, classInfo, deltaPacket, itemClassName, logChanges, newDataItem, nodeName, usesManualCommit

Fields inherited from class xp.data.ItemDataSource

classInfo, dataSourceBinding, id, name, readOnly

Fields inherited from class xp.system.DispatcherObject

parent

Property Summary

public
data (read)
Get or set the data object encapsulated by this datasource

public
data: Object (write)


public
inline: XMLNode (read, write)
sets inline data from Fluid*

public
items: Array (read, write)
Gets or sets the array encapsulated in this dataSource

public
length: Number (read-only)
The number of record in the list

public
list: Array (read, write)
Gets or sets the array encapsulated in this dataSource

public
lookupField: String (read, write)


public
position: Number (read, write)
The position of the current record pointer in the list The same as SelectedIndex

public
selectedIndex: Number (read, write)
Gets or set the current item’s index in the collection. The same as Position

Properties inherited from class xp.data.DataSource

currentItem, isEditing, isInserting, isValid, schema

Properties inherited from class xp.data.ItemDataSource

currentItem, data, isEmpty, length

Constructor

public
ListDataSource ( list: Array)
Create a new ListDataSource instance

Method Summary

public
addDataRelation ( parentColumns: Object, childSource: ListDataSource, childColumns: Object ): DataRelation
Adds a data relation to the data source

public
addItem ( item: Object ): Void
Adds a data item to the end of the list

public
addItemAt ( index: Number, item: Object ): Void
Adds a data item at a specified position

public
addItemsAt ( index: Number, items: Array ): Void
Insert a series of item starting at the given index

public
editField ( index: Number, fieldName: String, newData: Object ): Void
Edits one field in the non-current record

public
first ( ): Boolean
Move to the first record

public
getClass ( ): Function
Returns a reference to the components static class

public
getFieldValue ( index: Number, fieldName: String ): Object
Gets data in a user-editable format - relaxed return type

public
getItemAt ( index: Number ): Object
Retrieves a data item independent of the current cursor position-part of the IList interface

public
getIterator ( ): ListItemIterator
Gets an iterator for this list

public
getKeyValue ( item: Object, cols: Array ): Object
extract the key value from the record

public
isEmpty ( ): Boolean
Indicates whether the collection contains any items

public
isFirst ( ): Boolean
Is the current record the first record in the list

public
isLast ( ): Boolean
Is the current record the last record in the list

public
last ( ): Boolean
Move to the last record

public
locateById ( id: String ): Boolean
Indicates whether the collection contains any items

public
lookup ( key: String, select: Boolean ): Object


public
moveBy ( inc: Number ): Boolean
Move the record pointer by an increment

public
next ( ): Boolean
Move to the next record

public
prior ( ): Boolean
Move to the previous record

public
removeAll ( ): Array
Remove all items from the list

public
removeItem ( ): Void
Removes the current data item

public
removeItemAt ( index: Number ): Object
Remove a data item at the given index

public
removeItemsAt ( index: Number, len: Number ): Array
Remove a series of items from the list

public
replaceItem ( item: Object ): Void
Replace the current data item

public
replaceItemAt ( index: Number, item: Object ): Void
Replace a data item at the given index

public
setFieldValue ( index: Number, fieldName: String, newData: Object ): Void
Edits one field

public
setFilter ( filter: Function ): Void
Filters the items by calling a filter function which returns true if the items passes the filter

public
setKeyConstraint ( v: Object )


public
sortItems ( compareFunc: Function, options: Number ): Void
Sort the list using a custom function

public
sortItemsOn ( fieldName: String, options: Number ): Void
Sort the list items

Methods inherited from class xp.data.DataSource

applyChanges, applyUpdates, cancelChanges, checkSchema, commitChanges, createItem, deleteItem, editItem, getClass, insertItem, rollbackChanges, toString, validate

Methods inherited from class xp.data.ItemDataSource

addBinding, getBinding, getClass, refresh, updateViews

Methods inherited from class xp.system.DispatcherObject

addEventListener, removeEventListener, routeEvent



Field Documentation

canSort

public var canSort: Boolean
Does this list support sorting

classInfo

public static var classInfo: Object
A static class information object

Every class has an associated classInfo object that holds the version and other static information. The classInfo can be accessed either directly by referencing the static class or by calling getClass() on any class instance.

selectFirstOnLoad

public var selectFirstOnLoad: Boolean
Controls whether the first record in the dataSource is selected when the list loads

If this is not true the position of the current record is initially undefined


Property Documentation

data

public data (read)
Get or set the data object encapsulated by this datasource

data

public data: Object (write)

inline

public inline: XMLNode (read, write)
sets inline data from Fluid*

items

public items: Array (read, write)
Gets or sets the array encapsulated in this dataSource

length

public length: Number (read-only)
The number of record in the list

Overrides:

list

public list: Array (read, write)
Gets or sets the array encapsulated in this dataSource

lookupField

public lookupField: String (read, write)

position

public position: Number (read, write)
The position of the current record pointer in the list The same as SelectedIndex

selectedIndex

public selectedIndex: Number (read, write)
Gets or set the current item’s index in the collection. The same as Position


Constructor Documentation

ListDataSource

public function ListDataSource(list: Array)
Create a new ListDataSource instance

Parameters:
list
The array source

Method Documentation

addDataRelation

public function addDataRelation(parentColumns: Object,
 childSource: ListDataSource,
 childColumns: Object): DataRelation
Adds a data relation to the data source

Add a parent child data relation to this datasource.
This is called on the parent datasource.

Parameters:
parentColumns
parentCols The parent columns involved in the relationships
childSource
child The child DataSource
childColumns
childCols The child columns involved in the relationships
Returns:
The newly created DataRelation

addItem

public function addItem(item: Object): Void
Adds a data item to the end of the list

Parameters:
item
An object that contains data. This constitutes an item in a data provider.

addItemAt

public function addItemAt(index: Number,
 item: Object): Void
Adds a data item at a specified position

If index is outside the range of the list the item will be added to the end of the list. Changes via this method do not generate validation events

Parameters:
index
A number greater than or equal to 0. This number indicates the position at which to insert the item; it is the index of the new item.
item
An object containing the data for the item.

addItemsAt

public function addItemsAt(index: Number,
 items: Array): Void
Insert a series of item starting at the given index

Changes via this method do not generate validation events

Parameters:
index
A number greater than or equal to 0. This number indicates the position at which to insert the items; it is the starting index of the new items.
items
An array of objects containing the data for the items.

editField

public function editField(index: Number,
 fieldName: String,
 newData: Object): Void
Edits one field in the non-current record

Parameters:
index
the index of the item
fieldName
the name of the field to edit
newData
the new data for the field

first

public function first(): Boolean
Move to the first record

Returns:
Boolean true if the cursor position changed otherwise false

getClass

public function getClass(): Function
Returns a reference to the components static class

Overrides:

getFieldValue

public function getFieldValue(index: Number,
 fieldName: String): Object
Gets data in a user-editable format - relaxed return type

Parameters:
index
the index of the item
fieldName
the name of the field to edit

getItemAt

public function getItemAt(index: Number): Object
Retrieves a data item independent of the current cursor position-part of the IList interface

Parameters:
index
A number greater than or equal to 0 and less than DataProvider.length. This number is the index of the item to retrieve.
Returns:
The requested item

getIterator

public function getIterator(): ListItemIterator
Gets an iterator for this list

getKeyValue

public function getKeyValue(item: Object,
 cols: Array): Object
extract the key value from the record

isEmpty

public function isEmpty(): Boolean
Indicates whether the collection contains any items

Overrides:

isFirst

public function isFirst(): Boolean
Is the current record the first record in the list

isLast

public function isLast(): Boolean
Is the current record the last record in the list

Returns:
Boolean true if the cursor position changed otherwise false

last

public function last(): Boolean
Move to the last record

Returns:
Boolean true if the cursor position changed otherwise false

locateById

public function locateById(id: String): Boolean
Indicates whether the collection contains any items

Selects the collection item whose ID matches id.
This method returns true if the specified ID can be matched to an item in the collection; otherwise, it returns false.

Parameters:
id
A string identifier for the item in the collection to be located.
Returns:
A Boolean value

lookup

public function lookup(key: String,
 select: Boolean): Object

moveBy

public function moveBy(inc: Number): Boolean
Move the record pointer by an increment

Parameters:
inc
The amount to increment the record pointer by can be negative or positive
Returns:
Boolean true if the cursor position changed otherwise false

next

public function next(): Boolean
Move to the next record

Returns:
Boolean true if the cursor position changed otherwise false

prior

public function prior(): Boolean
Move to the previous record

Returns:
Boolean true if the cursor position changed otherwise false

removeAll

public function removeAll(): Array
Remove all items from the list

Changes via this method do not generate validation eventsremoves all items in the data provider. This method triggers the modelChanged event with the event name removeItems.

Returns:
the items removed

removeItem

public function removeItem(): Void
Removes the current data item

removeItemAt

public function removeItemAt(index: Number): Object
Remove a data item at the given index

Changes via this method do not generate validation events

Parameters:
index
A number greater than or equal to 0. This number is the index of the item to remove.
Returns:
the items removed

removeItemsAt

public function removeItemsAt(index: Number,
 len: Number): Array
Remove a series of items from the list

Changes via this method do not generate validation events

Parameters:
index
A number greater than or equal to 0. This number is the starting index of the items to remove.
len
The number of items to remove
Returns:
the items removed

replaceItem

public function replaceItem(item: Object): Void
Replace the current data item

Changes via this method do not generate validation events

Parameters:
item
An object that is the new item.

replaceItemAt

public function replaceItemAt(index: Number,
 item: Object): Void
Replace a data item at the given index

Changes via this method do not generate validation events

Parameters:
index
A number greater than or equal to 0. This number is the index of the item to change.
item
An object that is the new item.

setFieldValue

public function setFieldValue(index: Number,
 fieldName: String,
 newData: Object): Void
Edits one field

Parameters:
index
the index of the item
fieldName
the name of the field to edit
newData
the new data for the field

setFilter

public function setFilter(filter: Function): Void
Filters the items by calling a filter function which returns true if the items passes the filter

Parameters:
filter
A comparison function to be called for each record it should true if the record is to be included or false if the record is excluded.

setKeyConstraint

public function setKeyConstraint(v: Object)

sortItems

public function sortItems(compareFunc: Function,
 options: Number): Void
Sort the list using a custom function

Usage:
myLDS.sortItems([compareFunc], [options])

Parameters:
compareFunc
A reference to a function that compares two items to determine their sort order. For details, see Array.sort() in Flash ActionScript Language Reference.This parameter is optional.
options
Lets you perform multiple, different types of sorts on a single array without having to replicate the entire array or resort it repeatedly. This parameter is optional. The following are possible values for options: Array.DESCENDING, which sorts highest to lowest. Array.CASEINSENSITIVE, which sorts case-insensitively. Array.NUMERIC, which sorts numerically if the two elements being compared are numbers. If they aren’t numbers, use a string comparison (which can be case-insensitive if that flag is specified). You can combine these options into one value. For example, the following code combines options 3 and 1: array.sort (Array.NUMERIC | Array.DESCENDING)

sortItemsOn

public function sortItemsOn(fieldName: String,
 options: Number): Void
Sort the list items

Parameters:
fieldName
A string that specifies the name of the field to use for sorting.
If you want to sort on more than one field pass an array of fieldNames.
options
Lets you perform multiple, different types of sorts on a single array without having to replicate the entire array or resort it repeatedly. This parameter is optional. The following are possible values for options: Array.DESCENDING, which sorts highest to lowest. Array.CASEINSENSITIVE, which sorts case-insensitively. Array.NUMERIC, which sorts numerically if the two elements being compared are numbers. If they aren’t numbers, use a string comparison (which can be case-insensitive if that flag is specified). You can combine these options into one value. For example, the following code combines options 3 and 1: array.sort (Array.NUMERIC | Array.DESCENDING)

The documentation was generated from the following file:


Generated on 10/30/2005 9:34:02 PM by AS2Doc