Reputation: 12213
I've got some tabular data in angularjs I'm sorting with standard sort funtions. I want to know how to get the rows of a table that contain a certain value to show up first.
Item Category1 Category2
The Item
field is always unique, but there are multiple items that have the same value for Category1
.
Is there a way I can use a custom orderBy
function to get all the items that have a certain Category1
value to show up first?
Upvotes: 0
Views: 101
Reputation: 2905
To list all entries with a specific value first, just check for that value in your sort function and return a lower number for items with that value than other items. eg.
$scope.showValueFirst = function(item) {
return item.Category1 == 'matched value' ? 0 : 1;
}
Upvotes: 0
Reputation: 393
ngRepeat="item in items | orderBy:sortByCategory"
You could write a function like:
$scope.sortByCategory = function(item){
return (item.category1 < item.category2);
}
Upvotes: 1