Solved

angularjs orderby function question

Posted on 2014-11-19
2
270 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

Optimizing Cloud Backup for Low Bandwidth

With cloud storage prices going down a growing number of SMBs start to use it for backup storage. Unfortunately, business data volume rarely fits the average Internet speed. This article provides an overview of main Internet speed challenges and reveals backup best practices.

Question has a verified solution.

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

Nothing in an HTTP request can be trusted, including HTTP headers and form data.  A form token is a tool that can be used to guard against request forgeries (CSRF).  This article shows an improved approach to form tokens, making it more difficult to…
The article shows the basic steps of integrating an HTML theme template into an ASP.NET MVC project
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…

770 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