Solved

angularjs orderby function question

Posted on 2014-11-19
2
262 Views
Last Modified: 2014-12-04
I need a orderby function where if the usertype is a user, order by lastname, firstname.  If it is a person, orderby lastname, firstname, if it is a entity orderby the label.

They have the same object called contact, and the userType field distinguishes between user, person, and entity.  Also the order that it should show in is user, person, entity.
0
Comment
Question by:cbrune
2 Comments
 
LVL 96

Expert Comment

by:Bob Learned
ID: 40455248
I don't understand what you mean by "function".  Are you talking about a directive?
0
 
LVL 22

Accepted Solution

by:
ambience earned 500 total points
ID: 40457830
You probably need the orderBy filter for that purpose, which is documented here https://docs.angularjs.org/api/ng/filter/orderBy

According to the documentation, orderby accepts an array of function or string predicates. The first predicate in the array is used for sorting, but when two items are equivalent, the next predicate is used.

Filter is especially more relevant when sorting is needed for presentation only. However, using the $filter you can even get the builtin orderBy and invoke it directly in controller code.
0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Trouble inserting a variable  in javascript 7 42
how can display objects ? 3 24
Entity Framework 7 32
What namespace do I need to import? 2 13
Having worked on larger scale sites, we found out that you are bound to look at more scalable solutions to integrating widgets, code snippets or complete applications and mesh them into functional sites, in any given composition. To share some of…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
The viewer will learn the basics of jQuery, including how to invoke it on a web page. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery.: (CODE)
The viewer will learn the basics of jQuery including how to code hide show and toggles. Reference your jQuery libraries: (CODE) Include your new external js/jQuery file: (CODE) Write your first lines of code to setup your site for jQuery…

867 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

21 Experts available now in Live!

Get 1:1 Help Now