Created
June 26, 2012 11:14
-
-
Save sapandiwakar/2995193 to your computer and use it in GitHub Desktop.
Sorting tableview rows Titanium : 1
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/** | |
* 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