0

I want to filter my data in table after click the button. Here is my filter :

app.filter('eyeFilterFunction',function(){
    return function(data, from) {
        if (!from) return data;
        var items = [];
        angular.forEach(data, function(item){
            if(item.weight != from) {
                items.push(item);
            }
        });
        return items;
    };
});

And my plunker : http://plnkr.co/edit/s7tuhKXFSt0Yv5BfI4h0?p=preview

What i want - after click the button, only shows in table data with weight , where it is null in wehgit let it not show. Thanks for answers in advance!

1
  • I have added an answer. Commented Apr 28, 2018 at 8:59

2 Answers 2

1

try this

app.filter('eyeFilterFunction',function(){
    return function(data, from) {
        if (typeof from === 'undefined') return data;
        var items = [];
        for(var x of data){
          if(x.weight != from){
            items.push(x);
          }
        }
        return items;
    };
});
Sign up to request clarification or add additional context in comments.

1 Comment

and now how to remove this filter?
0

try this,

http://plnkr.co/edit/jNid2ZwiDNLrwGx2rnKh?p=preview9rnKsXvEtJrxhOYDMa7o?p=preview

app.filter('eyeFilterFunction', function() {
  return function(data, from) {
    if(!from) return data;
    return data.filter(i => i.weight != null);
  };
});

in template,

<tr ng-repeat="n in messages | eyeFilterFunction:filterText">

the button,

<button class="btn btn-clear btn-sm" ng-click="filterText = !filterText">Filter!</button>

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.