Class Recordset
- extends Base
The Recordset utility provides a standard way for dealing with
a collection of similar objects.
Provides the base Recordset implementation, which can be extended to add
additional functionality, such as custom indexing. sorting, and filtering.
Constructor
Recordset
(
config
)
- Parameters:
-
config
<Object>
Configuration object literal with initial attribute values
Properties inherited from Base:
Methods
private
Y.Record
_changeToRecord
(
obj
)
Helper method - it takes an object bag and converts it to a Y.Record
- Parameters:
-
obj
<Object || Y.Record>
Any objet literal or Y.Record instance
- Returns:
Y.Record
- A Record instance.
private
Y.Record
_defAddFn
(
)
Helper method called upon by add() - it is used to create a new record(s) in the recordset
- Returns:
Y.Record
- A Record instance.
private
void
_defAddHash
(
)
Method called whenever "recordset:add" event is fired. It adds the new record(s) to the hashtable.
private
void
_defEmptyFn
(
)
Helper method called upon by empty() - it is used to empty the recordset
private
void
_defEmptyHash
(
)
Method called whenever "recordset:empty" event is fired. It empties the hash table.
private
void
_defRemoveFn
(
)
Helper method called upon by remove() - it is used to remove record(s) from the recordset
private
void
_defRemoveHash
(
)
Method called whenever "recordset:remove" event is fired. It removes the record(s) from the recordset.
private
void
_defUpdateFn
(
)
Helper method called upon by update() - it is used to update the recordset
private
void
_defUpdateHash
(
)
Method called whenever "recordset:update" event is fired. It updates the record(s) by adding the new ones and removing the overwritten ones.
private
void
_recordSetUpdated
(
)
Event that is fired whenever the recordset is changed. Note that multiple simultaneous changes still fires this event once. (ie: Adding multiple records via an array will only fire this event once at the completion of all the additions)
private
void
_setHashTable
(
)
Sets up the hashtable with all the records currently in the recordset
private
void
_syncHashTable
(
)
Syncs up the private hash methods with their appropriate triggering events.
Y.Recordset
add
(
oData
,
index
)
Adds one or more Records to the RecordSet at the given index. If index is null, then adds the Records to the end of the RecordSet.
- Parameters:
-
oData
<Y.Record, Object Literal, Array>
A Y.Record instance, An object literal of data or an array of object literals
-
index
<Number>
(optional) Index at which to add the record(s)
- Returns:
Y.Recordset
- The updated recordset instance
Y.Recordset
empty
(
)
Empties the recordset
- Returns:
Y.Recordset
- The updated recordset instance
Number
getLength
(
)
Returns the length of the recordset
- Returns:
Number
- Number of records in the recordset
Y.Record
getRecord
(
i
)
Returns the record with particular ID or index
- Parameters:
-
i
<String, Number>
The ID of the record if a string, or the index if a number.
- Returns:
Y.Record
- An Y.Record instance
Y.Record
getRecordByIndex
(
i
)
Returns the record at a particular index
- Parameters:
-
i
<Number>
Index at which the required record resides
- Returns:
Y.Record
- An Y.Record instance
Array
getRecordsByIndex
(
index
,
range
)
Returns a range of records beginning at particular index
- Parameters:
-
index
<Number>
Index at which the required record resides
-
range
<Number>
(Optional) Number of records to retrieve. The default is 1
- Returns:
Array
- An array of Y.Record instances
Array
getValuesByKey
(
index
)
Returns an array of values for a specified key in the recordset
- Parameters:
-
index
<Number>
(optional) Index at which the required record resides
- Returns:
Array
- An array of values for the given key
protected
void
initializer
(
)
Publish default functions for events. Create the initial hash table.
Y.Recordset
remove
(
index
,
range
)
Removes one or more Records to the RecordSet at the given index. If index is null, then removes a single Record from the end of the RecordSet.
- Parameters:
-
index
<Number>
(optional) Index at which to remove the record(s) from
-
range
<Number>
(optional) Number of records to remove (including the one at the index)
- Returns:
Y.Recordset
- The updated recordset instance
Y.Recordset
update
(
data
,
index
)
Updates the recordset with the new records passed in. Overwrites existing records when updating the index with the new records.
- Parameters:
-
data
<Y.Record, Object Literal, Array>
A Y.Record instance, An object literal of data or an array of object literals
-
index
<Number>
(optional) The index to start updating from.
- Returns:
Y.Recordset
- The updated recordset instance
Methods inherited from EventTarget:
_getType,
_monitor,
_parseType,
addTarget,
after,
before,
bubble,
detach,
detachAll,
fire,
getEvent,
getTargets,
on,
once,
parseType,
publish,
removeTarget,
subscribe,
unsubscribe,
unsubscribeAll
Methods inherited from Attribute:
_addAttrs,
_addLazyAttr,
_defAttrChangeFn,
_fireAttrChange,
_getAttr,
_getAttrCfg,
_getAttrInitVal,
_getAttrs,
_getStateVal,
_isLazyAttr,
_normAttrVals,
_protectAttrs,
_set,
_setAttr,
_setAttrs,
_setAttrVal,
_setStateVal,
addAttr,
addAttrs,
attrAdded,
get,
getAttrs,
modifyAttr,
removeAttr,
reset,
set,
setAttrs
Methods inherited from Base:
_aggregateAttrs,
_defDestroyFn,
_defInitFn,
_destroyHierarchy,
_filterAttrCfs,
_getAttrCfgs,
_getClasses,
_initHierarchy,
_initHierarchyData,
_preInitEventCfg,
destroy,
init,
toString
Events
keyChange
(
event
)
Fires when the value for the configuration attribute 'key' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
recordsChange
(
event
)
Fires when the value for the configuration attribute 'records' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
tableChange
(
event
)
Fires when the value for the configuration attribute 'table' is changed. You can listen for the event using the
on method if you wish to be notified before the attribute's value has changed, or using the
after method if you wish to be notified after the attribute's value has changed.
- Parameters:
-
event
<Event.Facade>
An Event Facade object with the following attribute specific properties added: - prevVal
- The value of the attribute, prior to it being set
- newVal
- The value the attribute is to be set to
- attrName
- The name of the attribute being set
- subAttrName
- If setting a property within the attribute's value, the name of the sub-attribute property being set
Events inherited from Base:
Configuration Attributes
key
- string
The ID to use as the key in the hash table.
An array of records that the recordset is storing
A hash table where the ID of the record is the key, and the record instance is the value.
Configuration attributes inherited from Base: