Titanium Community Questions & Answer Archive

We felt that 6+ years of knowledge should not die so this is the Titanium Community Questions & Answer Archive

returning contacts by some order?

var people = Titanium.Contacts.getAllPeople();

for getAllPeople is there a way to return the list in some order.. like by fullName?

— asked September 30th 2010 by vincent youmans
  • contacts
0 Comments

3 Answers

  • Not sure this helps. It isn't exactly what you asked from what I can see but this call does accept Titanium.Contacts.CONTACTS_SORT_FIRST_NAME and Titanium.Contacts.CONTACTS_SORT_LAST_NAME to control the order of members in a contact group.

    http://developer.appcelerator.com/apidoc/mobile/latest/Titanium.Contacts.Group.sortedMembers-method.html

    — answered September 30th 2010 by John McKnight
    permalink
    1 Comment
    • can I get an example of how that would be used.

      — commented November 3rd 2010 by vincent youmans
  • While I don't know if Titanium has it build in, you can always take the returned object and then sort it yourself using a custom javascript sort. Try googling javascript sort and also look here the numeric sorting towards the bottom is a custom sort. Just use the field you want to sort by and do something like a.LastName - b.LastName.

    Here's a sort I implemented on the old contacts api

        contacts.sort(function (a, b) {
            var firstA = a.firstName.toLowerCase();
            var firstB =  b.firstName.toLowerCase();
            var lastA =a.lastName.toLowerCase();
            var lastB = b.lastName.toLowerCase();
    
            return ((firstA < firstB) ? -1 : ((firstA > firstB) ? 1 : ((lastA < lastB) ? -1 : ((lastA > lastB) ? 1 : 0))));
        });
    
    — answered September 30th 2010 by Mike Robinson
    permalink
    0 Comments
  • var people = Titanium.Contacts.getAllPeople();
    people.Contacts.CONTACTS_SORT_LAST_NAME;
    
    //Titanium.Contacts.CONTACTS_SORT_LAST_NAME
    

    I am trying to get the var people to return a sorted list of contacts.
    what am I doing wrong?

    — answered November 3rd 2010 by vincent youmans
    permalink
    0 Comments
The ownership of individual contributions to this community generated content is retained by the authors of their contributions.
All trademarks remain the property of the respective owner.