Whatever message this page gives is out now! Go check it out!
ListSort(list,sortType,[sortOrder=asc, delimiters=',' ,includeEmptyFields=false, localeSensitive=false])ListSort(list,callback)Parameter | Required/Optional | Default | Description |
list | Required | A list or a variable that contains one. | |
includeEmptyFields | Optional | no | Set to yes to include empty fields. |
localeSensitive | Optional | false | Specify if you wish to do a locale-sensitive sorting. The default value is false. |
sortType | Optional |
| |
sortOrder | Required | asc |
|
delimiters | Optional | , | A string or a variable that contains one. Characters that separate list elements. The default value is comma . If this parameter contains more than one character, ColdFusion uses the first character in the string as the delimiter, and ignores the rest. |
callback | Optional | A function that takes two elements of the list and returns 1, 0 or -1, if the first value is greater than, equal to, or less than the second value, respectively. |
<cfscript>
// case 1
myList1="12,23,107,19,1,65"
sortedNums=ListSort(myList1,"Numeric","asc",",")
writeOutput(sortedNums & "<br/>")
// case 2
myList2="23.75;-34,471:100,-9745"
sortedNums2=ListSort(myList2,"Numeric","asc",";:,")
writeOutput(sortedNums2 & "<br/>")
// case 3
myList3="hello;123,HELLO:jeans,-345,887;ColdFusion:coldfusion"
sortedMix=ListSort(myList3,"TextNoCase","asc",";,:")
writeOutput(sortedMix)
</cfscript><cfscript>
myList="ColdFusion,COLDFUSION,Cold Fusion,Coldfusion";
// define callback function
function callback(e1,e2){
return compareNoCase(e1,e2);
}
mySortedList=ListSort(myList,callback);
writeOutput(mySortedList);
</cfscript><cfscript>
listToSort = "d,C,b,A"
sortedList = listToSort.listSort(compareNoCase)
writeDump(sortedList)
</cfscript><cfscript>
listToSort = "d,C,b,A"
sortedList = listToSort.listSort(compare)
writeDump(sortedList)
</cfscript><cfscript>
list1 = "Brazil|Australia||Canada";
list2 = listSort(list=list1,callback=function(element1, element2) {
return element1.compare(element2);
}, delimiter="|", includeEmptyFields=true);
writeOutput(list2& "<br>");
list3 = listSort(list=list1,callback=function(element1, element2) {
return element1.compare(element2);
}, delimiter="|", includeEmptyFields=false);
writeOutput(list3& "<br>");
</cfscript><cfscript>
list1 = "5,8,,1,2";
list2 = listSort(list=list1,callback=function(element1, element2) {
return element1.compare(element2);
}, delimiter=",", includeEmptyFields=true);
writeOutput(list2&"<br>");
list3 = listSort(list=list1,callback=function(element1, element2) {
return element1.compare(element2);
}, delimiter=",", includeEmptyFields=false);
writeOutput(list3&"<br>");
</cfscript>