angularjs - Building a checkbox filter using ng-repeat -


i have json object i'm building checkboxes using ng-repeat orderby: 'name':

<div ng-controller="ctrl">     <ul>         <li ng-repeat="fruit in fruits | orderby:'name'">             <label>                 <input type="checkbox" name="{{fruit.name}}" id="{{fruit.name}}">                 {{fruit.name}}             </label>         </li>     <ul> </div> 

now want sort items first "checked" , alphabetically.

here's fiddle: http://jsfiddle.net/dqftw/67/

you should have additional column in data status default false(unchecked), or u needed. use ng-model data should below.

 $scope.fruits =             [{'name':'apple',status:false},         {'name':'mary',status:false},         {'name':'mike',status:false},         {'name':'adam',status:false},         {'name':'julie',status:false}]      } 

then html as

   <ul> <li ng-repeat="fruit in fruits | orderby:['!status','name']">     <label><input type="checkbox" name="{{fruit.name}}" ng-model="fruit.status" >{{fruit.name|uppercase}}</label></li> <ul> 

check below fiddle link. works perfect u needed, http://jsfiddle.net/dqftw/90/

@mickael updated 1 didn't work perfectly,


Comments

Popular posts from this blog

java - activate/deactivate sonar maven plugin by profile? -

python - TypeError: can only concatenate tuple (not "float") to tuple -

java - What is the difference between String. and String.this. ? -