return contacts array by lastName
var people = Titanium.Contacts.getAllPeople();… is there a way to return the array sorted by lastName?
2 Answers
-
I looked through the code and it seem you can only sort when you are retrieving users from a group.
if there is someone out there who knows differently, please let me know
-
Titanium.Contacts is a crock. It will crash your users' devices.
This is the only way I have been able to get a sorted name list:
var contacts = Titanium.Contacts.getAllPeople(); contacts.sort(sortByLastName); function sortByLastName(a, b) { var x = JSON.stringify(a.lastName).toUpperCase(); var y = JSON.stringify(b.lastName).toUpperCase(); return ((x < y) ? -1 : ((x > y) ? 1 : 0)); };
regards,
JH