Skip to content

Instantly share code, notes, and snippets.

@sapandiwakar
Created June 26, 2012 11:14
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save sapandiwakar/2995193 to your computer and use it in GitHub Desktop.
Save sapandiwakar/2995193 to your computer and use it in GitHub Desktop.
Sorting tableview rows Titanium : 1
/**
* Function that sorts the data using myComparator.
*/
function sort(data) {
data.sort(myComparator);
}
/**
* Comparator that defines order based on myValue in objects.
* @returns 1, -1, 0 denoting value in thisObject is greater than, less than or equal to value in thatObject
*/
function myComparator(thisObject, thatObject) {
if (thisObject.myValue > thatObject.myValue) {
return 1;
} else if (thisObject.myValue < thatObject.myValue) {
return -1;
}
return 0;
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment