Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to filter list using angularjs

I have an array of objects initially on load no filter should be applicable then on user selection combination list should be displayed accordingly.

Fiddle

I am not able to get what wrong did i done over here whole list i not displaying and only single selection works at a time. For single selection i used

 return $scope.filter[stat.userStatus] || noFilter($scope.filter);

I cannot make both selection work together.

like image 818
Kunal Vashist Avatar asked Dec 05 '14 09:12

Kunal Vashist


People also ask

How does filter work in AngularJS?

The “filter” Filter in AngularJS is used to filter the array and object elements and return the filtered items. In other words, this filter selects a subset (a smaller array containing elements that meet the filter criteria) of an array from the original array.

What is the correct way to apply multiple filters in AngularJS?

Using filters in view templates Filters can be applied to the result of another filter. This is called "chaining" and uses the following syntax: {{ expression | filter1 | filter2 | ... }} E.g. the markup {{ 1234 | number:2 }} formats the number 1234 with 2 decimal points using the number filter.

What is custom filter in AngularJS?

Introduction to AngularJS Custom Filter. In AngularJS filters are used to modify or update the data before rendering the data on view or UI. Filters are clubbed in expression or directives using pipe (|) symbol.

How do I filter in NG repeat?

The ng-repeat values can be filtered according to the ng-model in AngularJS by using the value of the input field as an expression in a filter. We can set the ng-model directive on an input field to filter ng-repeat values.

How to use filter in AngularJS?

In angulajs, filter is used get filtered subset of items from array items list based on user input filter key text. Syntax of using AngularJS Filter Following is the syntax of using filter in angularjs applications to search or filter items from array list. { {filterexpression | filter : expression}}

How to use filters in JavaScript?

Filters are generally added to the expressions by using the pipe (|) character. For example, the filter { { fullName | uppercase }} formats the fullName into the uppercase format. currency The number is formatted to currency format. date The date is specified to a specific format.

How to use nG-model on an input field in a filter?

By setting the ng-model directive on an input field, we can use the value of the input field as an expression in a filter. Type a letter in the input field, and the list will shrink/grow depending on the match:

How to use the nG-model and Ng-click directives on input fields?

By setting the ng-model directive on an input field, we can use the value of the input field as an expression in a filter. Type a letter in the input field, and the list will shrink/grow depending on the match: By adding the ng-click directive on the table headers, we can run a function that changes the sorting order of the array:


1 Answers

Filters can be chained together, like so:

<div ng-repeat="item in mylist | filter:filterByStatus | filter:filterByRole">

The filters run from left to right, with each filter passing the filtered array to the next filter.

Here is a fork of Mark's fiddle, demonstrating this technique: http://jsfiddle.net/2671uggu/

like image 115
j.wittwer Avatar answered Oct 03 '22 00:10

j.wittwer