How to sort by using multiple fields at same time in angular? fist by group and then by sub-group for Example
$scope.divisions = [{'group':1,'sub':1}, {'group':2,'sub':10}, {'group':1,'sub':2},{'group':1,'sub':20},{'group':2,'sub':1}, {'group':2,'sub':11}];
I wanted to display this as
1 - 1
1 - 2
1 - 20
2 - 1
2 - 10
2 - 11
<select ng-model="divs" ng-options="(d.group+' - '+d.sub) for d in divisions | orderBy:'group' | orderBy:'sub'" />
Syntax: SELECT * FROM table_name ORDER BY column_name; For Multiple column order, add the name of the column by which you'd like to sort records first. The column that is entered at first place will get sorted first and likewise.
An orderBy Filter in AngularJS is used to sort the given array to the specific order. The default order of sorting the string is in alphabetical order whereas the numbers are numerically sorted. By default, all the items are sorted in ascending order, if the ordering sequence is not specified.
In angularjs we can implement sorting for table columns by using ng-table module. Generally in angularjs if we want to implement sorting for table columns we need to write a lot of code but if we use ng-table module in angularjs applications it's very easy to implement sorting for table columns with few lines of code.
Please see this:
http://jsfiddle.net/JSWorld/Hp4W7/32/
<div ng-repeat="division in divisions | orderBy:['group','sub']">{{division.group}}-{{division.sub}}</div>
If you wants to sort on mulitple fields inside controller use this
$filter('orderBy')($scope.property_list, ['firstProp', 'secondProp']);
See also https://docs.angularjs.org/api/ng/filter/orderBy
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With