0

I have a enum defined in Typescript:

enum PriorityLevel {
High = <any>'High',
Normal = <any>'Normal',
Low = <any>'Low'}

Then in my html I have:

<button id= "assignmentBtn" type="button" ng-repeat="item in list.getItems()" class="btn" ng-class="list.getcolor(item)">
        {{item.description}}
</button>

Where each item has a PriorityLevel.

My question is that I want to sort this list by PriorityLevel, so that High is on top, then Normal and then Low. I tried to add

ng-repeat="item in list.getItems() | orderBy:'priority'"

But obviously, this orders the items alpabetically.

I quess I have to make a custom orderby function, but can anyone help me with how that should look in my case?

1 Answer 1

1

I quess I have to make a custom orderby function, but can anyone help me with how that should look in my case

Direct to a custom function in the controller:

ng-repeat="item in list.getItems() | orderBy:list.customOrder"

And customOrder:

customOrder = function(item) {
   return item.priority === 'High' ? 3
          : item.priority === 'Normal' ? 2 
          : 1
};
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.