3
Copyright 2011 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
7
YUI.add('recordset-filter', function(Y) {
10
* Plugin that provides the ability to filter through a recordset.
11
* Uses the filter methods available on Y.Array (see arrayextras submodule) to filter the recordset.
13
* @submodule recordset-filter
22
* Plugin that provides the ability to filter through a recordset.
23
* Uses the filter methods available on Y.Array (see arrayextras submodule) to filter the recordset.
24
* @class RecordsetFilter
26
function RecordsetFilter(config) {
27
RecordsetFilter.superclass.constructor.apply(this, arguments);
30
Y.mix(RecordsetFilter, {
33
NAME: "recordsetFilter",
41
Y.extend(RecordsetFilter, Y.Plugin.Base, {
45
Filter through the recordset with a custom filter function, or a key-value
49
@param {Function|String} filter A custom filter function or a string
50
representing the key to filter by.
51
@param {Any} [value] If filtering by key (_filter_ is a string), further
52
filter by a specific value.
53
@return {Recordset} A new filtered Recordset instance
55
filter: function (filter, value) {
56
var recs = this.get('host').get('records'),
59
//If a key-value pair is passed in, generate a custom function
60
if (value && Lang.isString(filter)) {
62
filter = function(item) {
63
return (item.getValue(key) === value);
67
//TODO: PARENT CHILD RELATIONSHIP
68
return new Y.Recordset({
69
records: YArray.filter(recs, filter)
74
The inverse of filter. Executes the supplied function on each item. Returns
75
a new Recordset containing the items that the supplied function returned
79
@param {Function} filter A boolean function, executed on each item.
80
@return {Recordset} A new Recordset instance containing the items on which
81
the supplied function returned false.
83
reject: function (filter) {
84
return new Y.Recordset({
85
records: YArray.reject(this.get('host').get('records'), filter)
90
Iterates over the Recordset, returning a new Recordset of all the elements
91
that match the supplied regular expression
94
@param {RegExp} pattern The regular expression to test against each record.
95
@return {Recordset} A Recordset instance containing all the items in the
96
collection that produce a match against the supplied regular
97
expression. If no items match, an empty Recordset instance is returned.
99
grep: function (pattern) {
100
return new Y.Recordset({
101
records: YArray.grep(this.get('host').get('records'), pattern)
105
//TODO: Add more pass-through methods to arrayextras
108
Y.namespace("Plugin").RecordsetFilter = RecordsetFilter;
111
}, '3.4.1' ,{requires:['recordset-base','array-extras','plugin']});