I am using order by of Angular for sorting but I want to sort data based on three different fields, i.e success
, in-progress
and failed
, without using any constant and variable directly from in-built function. Is there any way?
Asked
Active
Viewed 1,308 times
0
-
as I understand it you are looking for this post: http://stackoverflow.com/questions/17037524/orderby-multiple-fields-in-angular – christianalfoni Jul 28 '14 at 10:15
2 Answers
0
you can pass array of fields to orderBy
<div ng-repeat="row in list | orderBy:['param1','param2']">
....
</div>
EDIT
to do it in javascript
$scope.sortedList = $filter('orderBy')(list,['param1', 'param2']);
EDIT
in smart table
function customSortAlgorithm(arrayRef, sortPredicate, reverse) {
//do some stuff
return sortedArray;
}
scope.globalConfig = {
sortAlgorithm: customSortAlgorithm
};

harishr
- 17,807
- 9
- 78
- 125
-
hiii harish, actually i am using forEach to load the whole data something can be done with the help of sortPredicate of angular ?????in smart-table content i need this sorting. – Codiee Jul 28 '14 at 10:37
-
-
yes in smart table whole directive is loading and on particular column i want to perform this search. – Codiee Jul 28 '14 at 11:24
-
hello,my code is:::: isSortable : true, sortPredicate: function(dataRow){ if(dataRow.completedTableauConversionStatus === 3) return -1; else if(dataRow.completedTableauConversionStatus === 2) return 1; else if(dataRow.completedTableauConversionStatus === 4) return 2; } ---------------------------------------------------------------- here i am using status code but i can not constants like 1,2 3 so is there any other statement that i can return . – Codiee Jul 28 '14 at 11:28
0
If you want you can call a function to sort your data as you want.
you can call following custom 'orderBy'
$scope.sort = function(column,reverse) {
$scope.persons = $filter('orderBy')($scope.persons,column,reverse);
};
'$scope.persons' - is your collection of data you need to order 'column' - name of the column you want to sort data 'reverse'- bool value to reverse the order
and you can call this 'sort' function from your View(HTML) as below.
data-ng-click="sort('name',nameReverse)"

Sankalpa
- 41
- 5
-
-
smart table also has data source. what you want to do is pass your data source to above function. Or you can pass smart table 'rowCollection' to the above function. and you can call the function when header click. – Sankalpa Jul 28 '14 at 12:26