index.mustache revision 125a6c5e5913a2ffbc0e4589e241c7e868e6e0de
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney<div class="intro component">
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney The Recordset utility allows the storage and retrieval of objects with
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney similar properties.
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney{{>getting-started}}
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney<h2 id="using">Using Recordsets</h2>
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney<h3 id="basics">Recordset basics</h3>
3883a992e58e3629e15903ab299e20fce8483e2cJeff Conniff A Recordset in its simplest form is a collection of records, where records
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney can be considered to be object literals. Recordset allows the user to
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney handle this collection of records with a consistent API.
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney Recordset augments the functionality of <code>Y.Arraylist</code> but goes a
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney step further, by allowing the developer to quickly store and retrieve
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney objects with similar properties. Additional submodules can be plugged into
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney a <code>Y.Recordset</code> instance to enable sorting, filtering and
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney indexing by specific keys.
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney Initializing a Recordset is straight-forward:
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt SweeneyYUI().use("recordset-base", function(Y) {
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney var data = [
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney {a:3, b:2, c:1},
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney {a:9, b:8, c:7},
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney {a:1, b:2, c:3}
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney //Recordset is created with the objects from the data array
1f08a8488664773a7d96fa3a043a639692d2a5cbMatt Sweeney myRecordset = new Y.Recordset({records: data}),
anEmptyRecordset = new Y.Recordset();
A <code>Y.Recordset</code> can be filled with a single, or an array of
documentation for the <a href="../examples/recordset/recordset_basic.html">
myRecordset = new Y.Recordset({records:data});
myRecordset.add({key:"d", label:"Column D"});
myRecordset = new Y.Recordset({records:data});
myRecordset.remove(0,2);
myRecordset = new Y.Recordset({records:data});
myRecordset.update({key:"d", label:"Column D"}, 2);
myRecordset = new Y.Recordset({records:data});
<td><strong>added:</strong> an array of new records that were added (can contain a single record)<br/>
<td><strong>removed:</strong> an array of records that were removed (can contain a single record)<br/>
<td>Empty object bag, fired whenever records in the Recordset change (ie: they are added, removed, updated, or emptied)</td>
the <a href="../examples/recordset/recordset_sort.html">
If a key/value pair is passed in, returns a Recordset with records
that match the key/value pair. Supports a custom function for more
href="../examples/recordset/recordset_indexer.html"><code>RecordsetIndexer</code>