Donna McMann
Posts: 0
Joined: Tue Mar 12, 2013 6:43 pm

how to sort listview component when using the Contacts Service

I have created an app that loads my contacts from my iphone. When the list is displayed it is not sorted alphabetically. If I put the auto dividers on, they do end up in the correct letter but even the letters are not sorted.

Is there a way to sort the contacts before being displayed?

Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

how to sort listview component when using the Contacts Service

Dear Donna,

If you need to show sorted list you would need not to use mapping and ContactService in Tiggzi.
You would need to call Cordova functions via JavaScript (http://docs.phonegap.com/en/2.4.0/cor...), sort the array and create a list based on sorted data.

Donna McMann
Posts: 0
Joined: Tue Mar 12, 2013 6:43 pm

how to sort listview component when using the Contacts Service

Katya, Thank you for your reply but I did find a way to sort the list by using javascript on the success of invoking the Contact Service. Here is an example of the code:

function sortAlpha(a,b){
//return $(a).text().toLowerCase() $(b).text().toLowerCase() ? 1 : -1;
return $(a).find('[dsid="Name"]').text().toLowerCase() $(b).find('[dsid="Name"]').text().toLowerCase() ? 1 : -1;
};

Code: Select all

 $('[dsid="CustList"] li').sort(sortAlpha).appendTo('[dsid="CustList"]');
Kateryna Grynko
Posts: 0
Joined: Thu Nov 15, 2012 9:13 am

how to sort listview component when using the Contacts Service

Donna,
Thank you for sharing this :)

Return to “Issues”