2
YUI 3.10.3 (build 2fb5187)
3
Copyright 2013 Yahoo! Inc. All rights reserved.
4
Licensed under the BSD License.
5
http://yuilibrary.com/license/
8
YUI.add('recordset-filter', function (Y, NAME) {
11
* Plugin that provides the ability to filter through a recordset.
12
* Uses the filter methods available on Y.Array (see arrayextras submodule) to filter the recordset.
14
* @submodule recordset-filter
23
* Plugin that provides the ability to filter through a recordset.
24
* Uses the filter methods available on Y.Array (see arrayextras submodule) to filter the recordset.
25
* @class RecordsetFilter
27
function RecordsetFilter(config) {
28
RecordsetFilter.superclass.constructor.apply(this, arguments);
31
Y.mix(RecordsetFilter, {
34
NAME: "recordsetFilter",
42
Y.extend(RecordsetFilter, Y.Plugin.Base, {
46
Filter through the recordset with a custom filter function, or a key-value
50
@param {Function|String} filter A custom filter function or a string
51
representing the key to filter by.
52
@param {Any} [value] If filtering by key (_filter_ is a string), further
53
filter by a specific value.
54
@return {Recordset} A new filtered Recordset instance
56
filter: function (filter, value) {
57
var recs = this.get('host').get('records'),
60
//If a key-value pair is passed in, generate a custom function
61
if (value && Lang.isString(filter)) {
63
filter = function(item) {
64
return (item.getValue(key) === value);
68
//TODO: PARENT CHILD RELATIONSHIP
69
return new Y.Recordset({
70
records: YArray.filter(recs, filter)
75
The inverse of filter. Executes the supplied function on each item. Returns
76
a new Recordset containing the items that the supplied function returned
80
@param {Function} filter A boolean function, executed on each item.
81
@return {Recordset} A new Recordset instance containing the items on which
82
the supplied function returned false.
84
reject: function (filter) {
85
return new Y.Recordset({
86
records: YArray.reject(this.get('host').get('records'), filter)
91
Iterates over the Recordset, returning a new Recordset of all the elements
92
that match the supplied regular expression
95
@param {RegExp} pattern The regular expression to test against each record.
96
@return {Recordset} A Recordset instance containing all the items in the
97
collection that produce a match against the supplied regular
98
expression. If no items match, an empty Recordset instance is returned.
100
grep: function (pattern) {
101
return new Y.Recordset({
102
records: YArray.grep(this.get('host').get('records'), pattern)
106
//TODO: Add more pass-through methods to arrayextras
109
Y.namespace("Plugin").RecordsetFilter = RecordsetFilter;
112
}, '3.10.3', {"requires": ["recordset-base", "array-extras", "plugin"]});