Skip to content

Commit

Permalink
Can search on all columns except number type columns.
Browse files Browse the repository at this point in the history
  • Loading branch information
douglas-hirsh committed Feb 26, 2015
1 parent 28d683a commit 933be1d
Show file tree
Hide file tree
Showing 4 changed files with 26 additions and 5 deletions.
10 changes: 10 additions & 0 deletions client/views/items/itemlist.html
Expand Up @@ -15,6 +15,16 @@
<th class="two column wide">Price</th>
{{#if isLoggedIn}}<th></th>{{/if}}
</tr>
<tr>
<th class="two column wide">{{> itemsearch columnName='store'}}</th>
<th class="two column wide">{{> itemsearch columnName='name'}}</th>
<th class="two column wide"></th>
<th class="two column wide">{{> itemsearch columnName='weightType'}}</th>
<th class="two column wide"></th>
<th class="two column wide">{{> itemsearch columnName='qtyType'}}</th>
<th class="two column wide"></th>
{{#if isLoggedIn}}<th></th>{{/if}}
</tr>
</thead>
<tbody>
{{#each items}}
Expand Down
11 changes: 10 additions & 1 deletion client/views/items/itemsearch.js
@@ -1,5 +1,14 @@
Template.itemsearch.events({
'keyup .searchInput': _.throttle(function(e, t) {
Session.set('searchQuery', {name: t.$('.searchInput').val()});
var searchQuery = Session.get('searchQuery') || {};
searchQuery[this.columnName] = t.$('.searchInput').val();
Session.set('searchQuery', searchQuery);
},500)
});

Template.itemsearch.rendered=function(){
var searchQuery = Session.get('searchQuery') || {};
var searchColumnValue = searchQuery[this.data.columnName] || '';

this.$('.searchInput').val(searchColumnValue);
}
2 changes: 1 addition & 1 deletion client/views/layouts/layout.html
Expand Up @@ -5,7 +5,7 @@ <h1 class="header item">Price Book</h1>
{{> atNavButton}}
</div>
<div class="right menu">
{{> itemsearch}}
{{> itemsearch columnName='name'}}
</div>
</nav>
<div class="ui grid">
Expand Down
8 changes: 5 additions & 3 deletions server/publications/items/item.js
@@ -1,8 +1,10 @@
Meteor.publish("allItems", function (searchQuery) {
var mongoQuery = {};
_.each(_.keys(searchQuery), function(key){
mongoQuery[key] = {$regex: searchQuery[key], $options: 'i'};
});
if(searchQuery){
_.each(_.keys(searchQuery), function(key){
mongoQuery[key] = {$regex: searchQuery[key], $options: 'i'};
});
}

return Items.find(mongoQuery,{limit:10});
});

0 comments on commit 933be1d

Please sign in to comment.