Page 1 of 1

how to sort listview component when using the Contacts Service

Posted: Tue Mar 12, 2013 6:43 pm
by Donna McMann

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?


how to sort listview component when using the Contacts Service

Posted: Tue Mar 12, 2013 9:02 pm
by Kateryna Grynko

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.


how to sort listview component when using the Contacts Service

Posted: Tue Mar 12, 2013 9:17 pm
by Donna McMann

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"]');

how to sort listview component when using the Contacts Service

Posted: Tue Mar 12, 2013 10:18 pm
by Kateryna Grynko

Donna,
Thank you for sharing this :)