sort
sort
This tag provides "anonymous comparison function" sorting
functionality using the quick sort algorithm. It is useful for situations where
the sort definition is too complex for the native functions. The quick
sort algorithm has been abstracted so that the comparisons between items can be
performed by the code enclosed by the tag. That code is executed for each
comparison. Note: This tag DOES alter array type source sets.
Metadata
Examples
<cfset values = arraynew(1) />
<cfset values[1] = structnew() />
<cfset values[1].a = 10 />
<cfset values[1].b = 30 />
<cfset values[2] = structnew() />
<cfset values[2].a = 25 />
<cfset values[2].b = 5 />
<cfset values[3] = structnew() />
<cfset values[3].a = 15 />
<cfset values[3].b = 20 />
<misc:sort values="#values#">
<cfset sendback = max(value2.a,value2.b) - max(value1.a,value1.b) />
</misc:sort>
<cfdump var="#result#" />
Attributes
Name |
Type |
Required |
Default |
Options |
Description |
values |
string |
No |
|
|
The source set. Can be a list, array, or struct. |
value1 |
string |
No |
value1 |
|
The variable that will contain the first value to be compared for an iteration. Defaults to "value1" |
value2 |
string |
No |
value2 |
|
The variable that will contain the second value to be compared for an iteration. Defaults to "value2" |
sendback |
string |
No |
sendback |
|
The variable that will contain the result of the comparison. Should be set to 0 for "equal" values, less than 0 if the first value is "less" than the second, and more than 0 if the first value is "more" than the second. Defaults to "sendback" |
result |
string |
No |
result |
|
The result of the sort. For lists and arrays this is the sorted set. For structs this is an ordered list of keys. |