4D v17.4collection.orderBy( ) | 
            ||||||||||||||
                 
                
  | 
                
			
                    
                         
    4D v17.4
 
collection.orderBy( ) 
                                
                                
        
 | 
                |||||||||||||
| Constant | Type | Value | Comment | 
| ck ascending | Longint | 0 | Elements are ordered in ascending order (default) | 
| ck descending | Longint | 1 | Elements are ordered in descending order | 
If the collection contains elements of different types, they are first grouped by type and sorted afterwards. Types are returned in the following order:
Ordering a collection of numbers in ascending and descending order:
 C_COLLECTION($c;$c2;$3)
 $c:=New collection
 For($vCounter;1;10)
    $c.push(Random)
 End for
 $c2:=$c.orderBy(ck ascending)
 $c3:=$c.orderBy(ck descending)Ordering a collection of objects based on a text formula with property names:
 C_COLLECTION($c)
 $c:=New collection
 For($vCounter;1;10)
    $c.push(New object("id";$vCounter;"value";Random))
 End for
 $c2:=$c.orderBy("value desc")
 $c2:=$c.orderBy("value desc, id")
 $c2:=$c.orderBy("value desc, id asc")Ordering a collection of objects with a property path:
 C_COLLECTION($c)
 $c:=New collection
 $c.push(New object("name";"Cleveland";"phones";New object("p1";"01";"p2";"02")))
 $c.push(New object("name";"Blountsville";"phones";New object("p1";"00";"p2";"03")))
 $c2:=$c.orderBy("phones.p1 asc")Ordering a collection of objects using a collection of criteria objects:
 C_COLLECTION($crit;$c)
 $crit:=New collection
 $c:=New collection
 For($vCounter;1;10)
    $c.push(New object("id";$vCounter;"value";Random))
 End for
 $crit.push(New object("propertyPath";"value";"descending";True))
 $crit.push(New object("propertyPath";"id";"descending";False))
 $c2:=$c.orderBy($crit)Ordering with a property path:
 C_COLLECTION($crit;$c)
 $c:=New collection
 $c.push(New object("name";"Cleveland";"phones";New object("p1";"01";"p2";"02")))
 $c.push(New object("name";"Blountsville";"phones";New object("p1";"00";"p2";"03")))
 $crit:=New collection(New object("propertyPath";"phones.p2";"descending";True))
 $c2:=$c.orderBy($crit)
	Product:  4D
	Theme:  Collections
	
        
        
	
	
	4D Language Reference ( 4D v17)
	
	
	
	
	4D Language Reference ( 4D v17.1)
	
	4D Language Reference ( 4D v17.2)
	
	4D Language Reference ( 4D v17.3)
	
	4D Language Reference ( 4D v17.4)
	
	
Add a comment