Skip to content

Commit

Permalink
add in default search columns property
Browse files Browse the repository at this point in the history
  • Loading branch information
urkle committed Apr 3, 2015
1 parent 8c1c6fd commit b8b74f2
Show file tree
Hide file tree
Showing 4 changed files with 21 additions and 1 deletion.
1 change: 1 addition & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -73,6 +73,7 @@ Features/problems I'll implement/fix in the future. (issues about 'em will be cl
* [jkeyes](https://github.com/jkeyes) / [John Keyes](http://keyes.ie/)
* [samosad](https://github.com/samosad) / Alexey Tabakman
* [Page-](https://github.com/Page-)
* [urkle](https://github.com/urkle) / Edward Rudd

Built with [Component](https://github.com/component/component) which is created by [TJ Holowaychuk](https://github.com/visionmedia).

Expand Down
1 change: 1 addition & 0 deletions index.js
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ var List = function(id, options, values) {
self.matchingItems = [];
self.searched = false;
self.filtered = false;
self.searchColumns = undefined;
self.handlers = { 'updated': [] };
self.plugins = {};
self.helpers = {
Expand Down
4 changes: 3 additions & 1 deletion src/search.js
Original file line number Diff line number Diff line change
Expand Up @@ -26,7 +26,9 @@ module.exports = function(list) {
}
},
setColumns: function() {
columns = (columns === undefined) ? list.valueNames : columns;
if (columns === undefined) {
columns = (list.searchColumns === undefined) ? prepare.toArray(list.items[0].values()) : list.searchColumns;
}
},
setSearchString: function(s) {
s = toString(s).toLowerCase();
Expand Down
16 changes: 16 additions & 0 deletions test/test.search.js
Original file line number Diff line number Diff line change
Expand Up @@ -69,6 +69,22 @@ describe('Search', function() {
});
});


describe('Default search columns', function() {
it('should find in the default match column', function() {
list.searchColumns = ['name'];
var result = list.search('jonny');
expect(result.length).to.equal(1);
expect(result[0]).to.eql(jonny);
});
it('should not find in the default match column', function() {
list.searchColumns = ['born'];
var result = list.search('jonny');
expect(result.length).to.equal(0);
});
});


describe('Specfic columns', function() {
it('should find match in column', function() {
var result = list.search('jonny', [ 'name' ]);
Expand Down

0 comments on commit b8b74f2

Please sign in to comment.