Nayeem Mansoori
Nayeem Mansoori

Reputation: 831

Filter data on the basis of dropdown selection in Angular JS

I want to filter data on the basis of city dropdown alphabetical filter working fine but when i used dropdown and fiter dropdown selection then it will return wrong data please check my code here

[http://jsfiddle.net/Nayeem_Mansoori/yhy7hdrh/][1]

please help me.

Upvotes: 2

Views: 156

Answers (2)

Bruno Gomes
Bruno Gomes

Reputation: 1425

When I want to filter one field only o do like it:

<li ng-repeat="cust in Customer | filter: { Name: myfilters } | orderBy: Name">{{cust.Name}}</li>

filter by properties use filter: { Name: myfilters }

http://jsfiddle.net/yhy7hdrh/4/

--- Some time later ---

I think I understand, chosing a city you want to filter by letter the Name of customer... http://jsfiddle.net/yhy7hdrh/8/

Upvotes: 1

Kalhan.Toress
Kalhan.Toress

Reputation: 21901

I think u made a smallllll mistake :)

use like this

<li ng-repeat="cust in Customer | filter: myfilters | orderBy: 'Name'">{{cust.Name}}</li>

please put the Name as a string in orderBy as 'Name'

UPDATED FIDDLE

in order to filter by those two drop downs you need two separate filters, in angular its so simple as below line,

<li ng-repeat="cust in Customer | filter:selectedValue | filter:CityselectedValue | orderBy: 'Name'">

first it filter in selectedValue which is the first dropdown, and the second filter filters the results according to second dropdown.

UPDATED FIDDLE

more specifically use can use like this,

first dropdown

    <select ng-model="selectedValue.Name" n..

second dropdown

    <select ng-model="selectedValue.City" ng-opti..

in ng-repeat

<li ng-repeat="cust in Customer | filter:selectedValue | orderBy: 'Name'">

FIDDLE

Upvotes: 0

Related Questions