From 1f8b80678f3b61343a9752b768b7904ccb9d7bc4 Mon Sep 17 00:00:00 2001 From: Andrea Mannocci Date: Fri, 26 Jun 2015 12:13:46 +0200 Subject: [PATCH] Update angular-deckgrid.js I proposed a patch adding filtering capabilities to your great directive. I hope i works fine for you. As i wrote in a previous message on issue https://github.com/akoenig/angular-deckgrid/issues/39 Basically I injected `$filter` dependency in the module and used it in ```javascript Deckgrid.prototype.$$createColumns = function $$createColumns () { /*...*/ angular.forEach($filter('filter')(this.$$scope.model, this.$$scope.filter), function onIteration (card, index) { /*...*/ } /*...*/ } ``` in order to filter `source` attribute by a new directive attribute (called `filter`) for which I registered a new watcher ```javascript filterWatcher = this.$$scope.$watchCollection('filter', this.$$onModelChange.bind(this)); this.$$watchers.push(filterWatcher); ``` Apologies for any inconvenience.. I'm a github newbie.. --- angular-deckgrid.js | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/angular-deckgrid.js b/angular-deckgrid.js index e57bda8..229b27f 100644 --- a/angular-deckgrid.js +++ b/angular-deckgrid.js @@ -60,7 +60,8 @@ angular.module('akoenig.deckgrid').factory('DeckgridDescriptor', [ ''; this.scope = { - 'model': '=source' + 'model': '=source', + 'filter': '=filter' }; // @@ -163,8 +164,9 @@ angular.module('akoenig.deckgrid').factory('Deckgrid', [ '$window', '$log', + '$filter', - function initialize ($window, $log) { + function initialize ($window, $log, $filter) { 'use strict'; @@ -174,7 +176,8 @@ angular.module('akoenig.deckgrid').factory('Deckgrid', [ */ function Deckgrid (scope, element) { var self = this, - watcher, + watcher, + filterWatcher, mql; this.$$elem = element; @@ -196,9 +199,11 @@ angular.module('akoenig.deckgrid').factory('Deckgrid', [ // Register model change. // watcher = this.$$scope.$watchCollection('model', this.$$onModelChange.bind(this)); - this.$$watchers.push(watcher); + filterWatcher = this.$$scope.$watchCollection('filter', this.$$onModelChange.bind(this)); + this.$$watchers.push(filterWatcher); + // // Register media query change events. // @@ -304,8 +309,7 @@ angular.module('akoenig.deckgrid').factory('Deckgrid', [ } this.$$scope.columns = []; - - angular.forEach(this.$$scope.model, function onIteration (card, index) { + angular.forEach($filter('filter')(this.$$scope.model, this.$$scope.filter), function onIteration (card, index) { var column = (index % self.$$scope.layout.columns) | 0; if (!self.$$scope.columns[column]) {