# Yahoo! UI Library

### DataTable Widget 2.8.0r4

Yahoo! UI Library > datatable > YAHOO.widget.RecordSet
Search:
Filters Show Private Show Protected Show Deprecated

## Class YAHOO.widget.RecordSet

A RecordSet defines and manages a set of Records.

### Constructor

YAHOO.widget.RecordSet `( data )`

Parameters:
  `data <Object || Object[]>` An object literal or an array of data.

### Properties

#### _length - `private Number`

Internal counter of how many Records are in the RecordSet.
Deprecated: No longer used

#### _sId - `private String`

Unique String identifier assigned at instantiation.

#### RecordSet._nCount - `private static Number`

Internal class variable to name multiple Recordset instances.

### Methods

#### _addRecord

`private YAHOO.widget.Record _addRecord ( oData , index )`
Adds one Record to the RecordSet at the given index. If index is null, then adds the Record to the end of the RecordSet.

Parameters:
  `oData <Object>` An object literal of data.
  `index <Number>` (optional) Position index.

Returns: `YAHOO.widget.Record`
  A Record instance.

#### _deleteRecord

`private void _deleteRecord ( index , range )`
Deletes Records from the RecordSet at the given index. If range is null, then only one Record is deleted.

Parameters:
  `index <Number>` Position index.
  `range <Number>` (optional) How many Records to delete

Returns: `void`

#### _setRecord

`private YAHOO.widget.Record _setRecord ( oData , index )`
Sets/replaces one Record to the RecordSet at the given index. Existing Records with higher indexes are not shifted. If no index specified, the Record is added to the end of the RecordSet.

Parameters:
  `oData <Object>` An object literal of data.
  `index <Number>` (optional) Position index.

Returns: `YAHOO.widget.Record`
  A Record instance.

#### addRecord

`YAHOO.widget.Record addRecord ( oData , index )`
Adds one Record to the RecordSet at the given index. If index is null, then adds the Record to the end of the RecordSet.

Parameters:
  `oData <Object>` An object literal of data.
  `index <Number>` (optional) Position index.

Returns: `YAHOO.widget.Record`
  A Record instance.

#### addRecords

`YAHOO.widget.Record[] addRecords ( aData , index )`
Adds multiple Records at once to the RecordSet at the given index with the given object literal data. If index is null, then the new Records are added to the end of the RecordSet.

Parameters:
  `aData <Object[]>` An object literal data or an array of data object literals.
  `index <Number>` (optional) Position index.

Returns: `YAHOO.widget.Record[]`
  An array of Record instances.

#### deleteRecord

`Object deleteRecord ( index , range )`
Removes the Record at the given position index from the RecordSet. If a range is also provided, removes that many Records, starting from the index. Length of RecordSet is correspondingly shortened.

Parameters:
  `index <Number>` Record's RecordSet position index.
  `range <Number>` (optional) How many Records to delete.

Returns: `Object`
  A copy of the data held by the deleted Record.

#### deleteRecords

`Object[] deleteRecords ( index , range )`
Removes the Record at the given position index from the RecordSet. If a range is also provided, removes that many Records, starting from the index. Length of RecordSet is correspondingly shortened.

Parameters:
  `index <Number>` Record's RecordSet position index.
  `range <Number>` (optional) How many Records to delete.

Returns: `Object[]`
  An array of copies of the data held by the deleted Records.

#### getId

`String getId ( )`
Returns unique name of the RecordSet instance.

Returns: `String`
  Unique name of the RecordSet instance.

#### getLength

`Number getLength ( )`
Returns the number of Records held in the RecordSet.

Returns: `Number`
  Number of records in the RecordSet.

#### getRecord

`YAHOO.widget.Record getRecord ( record )`
Returns Record by ID or RecordSet position index.

Parameters:
  `record <YAHOO.widget.Record | Number | String>` Record instance, RecordSet position index, or Record ID.

Returns: `YAHOO.widget.Record`
  Record object.

#### getRecordIndex

`Number getRecordIndex ( oRecord )`
Returns current position index for the given Record.

Parameters:
  `oRecord <YAHOO.widget.Record>` Record instance.

Returns: `Number`
  Record's RecordSet position index.

#### getRecords

`YAHOO.widget.Record[] getRecords ( index , range )`
Returns an array of Records from the RecordSet.

Parameters:
  `index <Number>` (optional) Recordset position index of which Record to start at.
  `range <Number>` (optional) Number of Records to get.

Returns: `YAHOO.widget.Record[]`
  Array of Records starting at given index and length equal to given range. If index is not given, all Records are returned.

#### hasRecords

`Boolean hasRecords ( index , range )`
Returns a boolean indicating whether Records exist in the RecordSet at the specified index range. Returns true if and only if a Record exists at each index in the range.

Parameters:
  `index <object>`
  `range <object>`

Returns: `Boolean`
  true if all indices are populated in the RecordSet

#### replaceRecords

`YAHOO.widget.Record || YAHOO.widget.Record[] replaceRecords ( data )`
Replaces all Records in RecordSet with new object literal data.

Parameters:
  `data <Object || Object[]>` An object literal of data or an array of data object literals.

Returns: `YAHOO.widget.Record || YAHOO.widget.Record[]`
  A Record instance or an array of Records.

#### reset

`void reset ( )`
Deletes all Records from the RecordSet.

Returns: `void`

#### reverseRecords

`YAHOO.widget.Record[] reverseRecords ( )`
Reverses all Records, so ["one", "two", "three"] becomes ["three", "two", "one"].

Returns: `YAHOO.widget.Record[]`
  Reverse-sorted array of Records.

#### setRecord

`YAHOO.widget.Record setRecord ( oData , index )`
Sets or replaces one Record to the RecordSet at the given index. Unlike addRecord, an existing Record at that index is not shifted to preserve it. If no index is specified, it adds the Record to the end of the RecordSet.

Parameters:
  `oData <Object>` An object literal of data.
  `index <Number>` (optional) Position index.

Returns: `YAHOO.widget.Record`
  A Record instance.

#### setRecords

`YAHOO.widget.Record[] setRecords ( aData , index )`
Sets or replaces multiple Records at once to the RecordSet with the given data, starting at the given index. If index is not specified, then the new Records are added to the end of the RecordSet.

Parameters:
  `aData <Object[]>` An array of object literal data.
  `index <Number>` (optional) Position index.

Returns: `YAHOO.widget.Record[]`
  An array of Record instances.

#### sortRecords

`YAHOO.widget.Record[] sortRecords ( fnSort , desc , field )`
Sorts all Records by given function. Records keep their unique IDs but will have new RecordSet position indexes.

Parameters:
  `fnSort <Function>` Reference to a sort function.
  `desc <Boolean>` True if sort direction is descending, false if sort direction is ascending.
  `field <String>` The field to sort by, from sortOptions.field

Returns: `YAHOO.widget.Record[]`
  Sorted array of Records.

#### toString

`String toString ( )`
Public accessor to the unique name of the RecordSet instance.

Returns: `String`
  Unique name of the RecordSet instance.

#### updateKey

`void updateKey ( )`

Returns: `void`

Deprecated Use updateRecordValue

#### updateRecord

`YAHOO.widget.Record updateRecord ( record , oData )`
Updates given Record with given data.

Parameters:
  `record <YAHOO.widget.Record | Number | String>` A Record instance, a RecordSet position index, or a Record ID.
  `oData <Object>` Object literal of new data.

Returns: `YAHOO.widget.Record`
  Updated Record, or null.

#### updateRecordValue

`void updateRecordValue ( record , sKey , oData )`
Sets given Record at given key to given data.

Parameters:
  `record <YAHOO.widget.Record | Number | String>` A Record instance, a RecordSet position index, or a Record ID.
  `sKey <String>` Key name.
  `oData <Object>` New data.

Returns: `void`

### Events

#### keyUpdateEvent

`keyUpdateEvent ( )`
Deprecated Use recordValueUpdateEvent

#### recordAddEvent

`recordAddEvent ( oArgs.record , oArgs.data )`
Fired when a new Record is added to the RecordSet.

Parameters:
  `oArgs.record <YAHOO.widget.Record>` The Record instance.
  `oArgs.data <Object>` Data added.

#### recordDeleteEvent

`recordDeleteEvent ( oArgs.data , oArgs.index )`
Fired when a Record is deleted from the RecordSet.

Parameters:
  `oArgs.data <Object>` A copy of the data held by the Record, or an array of data object literals if multiple Records were deleted at once.
  `oArgs.index <Object>` Index of the deleted Record.

#### recordsAddEvent

`recordsAddEvent ( oArgs.records , oArgs.data )`
Fired when multiple Records are added to the RecordSet at once.

Parameters:
  `oArgs.records <YAHOO.widget.Record[]>` An array of Record instances.
  `oArgs.data <Object[]>` Data added.

#### recordsDeleteEvent

`recordsDeleteEvent ( oArgs.data , oArgs.index )`
Fired when multiple Records are deleted from the RecordSet at once.

Parameters:
  `oArgs.data <Object[]>` An array of data object literals copied from the Records.
  `oArgs.index <Object>` Index of the first deleted Record.

#### recordSetEvent

`recordSetEvent ( oArgs.record , oArgs.data )`
Fired when a Record is set in the RecordSet.

Parameters:
  `oArgs.record <YAHOO.widget.Record>` The Record instance.
  `oArgs.data <Object>` Data added.

#### recordsSetEvent

`recordsSetEvent ( oArgs.records , oArgs.data )`
Fired when multiple Records are set in the RecordSet at once.

Parameters:
  `oArgs.records <YAHOO.widget.Record[]>` An array of Record instances.
  `oArgs.data <Object[]>` Data added.

#### recordUpdateEvent

`recordUpdateEvent ( oArgs.record , oArgs.newData , oArgs.oldData )`
Fired when a Record is updated with new data.

Parameters:
  `oArgs.record <YAHOO.widget.Record>` The Record instance.
  `oArgs.newData <Object>` New data.
  `oArgs.oldData <Object>` Old data.

#### recordValueUpdateEvent

`recordValueUpdateEvent ( oArgs.record , oArgs.key , oArgs.newData , oArgs.oldData )`
Fired when a Record value is updated with new data.

Parameters:
  `oArgs.record <YAHOO.widget.Record>` The Record instance.
  `oArgs.key <String>` The updated key.
  `oArgs.newData <Object>` New data.
  `oArgs.oldData <Object>` Old data.

#### resetEvent

`resetEvent ( )`
Fired when all Records are deleted from the RecordSet at once.

Copyright © 2009 Yahoo! Inc. All rights reserved.