2

I have a button in my view. When I press my button I want to filter my table. My table have element called market it can be "ios" or "android". When I press "ios" button I want to show only data which have "ios" as market. In default table view all data (both ios and android).

button

<button ng-click="applyiosfilter()">Search</search>

table

<tr dir-paginate="datad in downloadsdata|filter:downloadfilter"> ...
</tr>

arrays for sore data

$scope.downloadsdata = [];
$scope.downloadfilter = [];

add data in to scope

$scope.applyiosfilter = function() {
    angular.forEach($scope.downloadsdata, function(value, key) {
        if(value.market==='ios') {
            $scope.downloadfilter[key] = $scope.downloadsdata[key];
        }
    });
};

1 Answer 1

2

You could try filter function as:

<button ng-click="applyiosfilter()">Search</search>
<tr dir-paginate="datad in downloadsdata|filter:applyfilter"> ...</tr>

$scope.applyiosfilter = function() {
    $scope.applyfilter = function(datad) { 
        return datad.Market.toLowerCase().indexOf('ios') != -1    
   };
};

EDIT: This will be fired only when the button is clicked.

Sign up to request clarification or add additional context in comments.

3 Comments

this is not return correct value.how datad get data? data is in "value" variable in forEach loop
what is the meaning of != -1 here?
if the string does not match your query('ios'), it would return -1, the whole expression evaluates to false and that item is not part of the filtered array.

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.