Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

angularjs orderby function question

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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

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.
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
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…

789 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