0

I'm using angular to create a search property form, and I've got a select box with amount of bedrooms, how can I create a greater then filter? (for example: when 2 bedrooms selected, display all properties with 2 bedrooms or more)

The select box:

<select class="form-control" 
        name="bedrooms" 
        ng-model="Bedrooms" 
        ng-options="property.data.SubType as (property.data.Bedrooms + ' Bedrooms ('+ property.count +')') for property in properties  | unique:'Bedrooms' | orderBy:'data.Bedrooms'">
        <option value="">Minimum Bedrooms</option>
</select>  

And the filter:

<tr ng-repeat="property in filtered = (properties | filterMultiple:{Address: Address, SubArea:SubArea, SubType:SubType} | filter:{Bedrooms:Bedrooms})|  orderBy:Address">  

This is my JSFiddle

tmt
  • 7,611
  • 4
  • 32
  • 46
Marc Geurts
  • 39
  • 1
  • 6
  • duplicate of http://stackoverflow.com/questions/24081004/angular-ng-repeat-filter-when-value-is-greater-than – Vinay K Mar 23 '15 at 11:11

1 Answers1

2

http://jsfiddle.net/odpw6c6q/43/

In ng-options use ng-options="property.data.Bedrooms as instead of ng-options="property.data.SubType as because data.Bedrooms is the property that contains number of bedrooms which should be stored in ng-model

In scope add this function

//Filter Function
    $scope.greaterThan = function(bedrooms) {
        return function(item) {                          
            if ( item['Bedrooms'] > bedrooms) {                
                return true;
            } else {                
                return false;
            }
        }
    };

In ng-repeat use filter: greaterThan(Bedrooms) instead of filter:{Bedrooms:Bedrooms}

Vamsi
  • 9,510
  • 6
  • 38
  • 46
  • Thanks for your help! do you know how I can improve the filter to work better? at the moment, when some areas are selected, and then select a type, the rest of the options don't work anymore. here's my updated [JSFiddle](http://jsfiddle.net/marcgeurts/odpw6c6q/) – Marc Geurts Mar 23 '15 at 12:13
  • It looks fine. What exactly is not working? You can vote and accept my answer if it is helpful :) – Vamsi Mar 23 '15 at 12:24