javascript - Order data before selecting an option in dropdown -
i have dropdown options can order data in html:
<select ng-model="sortorder" ng-options="option.value option.name item in options"></select>
further have code populates data ng-repeat , uses sortorder model sort data dropdown options:
<div ng-repeat="hello in worlds" | filter:searchquery | orderby: sortorder"
it works fine , data gets sorted options in dropdown order data in alphabetical order before click on option in dropdown list. or maybe option can selected default , sorts data. i've been searching answer here on stackoverflow haven't been able find any.
assuming following values in sortorder
model:
$scope.options = [ { name: 'name' value: 'name' }, { name: 'address' value: 'address' } ];
where name
, address
properties of worlds
model.
this takes care of sortby
- need sortin
feature - ascending or descending. use model that:
$scope.sortascending = false;
thus, select dropdown be:
<select ng-model="sortorder" ng-options="item.value item.name item in options"></select>
and repeated elements be:
<div ng-repeat="hello in worlds" | filter:searchquery | orderby:sortorder:sortascending"></div>
now, in order have default sortby
, need use same reference - way angularjs pick value , bind correctly
$scope.sortorder = $scope.options[0].value;
this set default sort order name
property.
Comments
Post a Comment