This is the legacy 4D documentation web site. Documentations are progressively being moved to developer.4d.com

Home

 
4D v19.8
entitySelection.orderBy( )

entitySelection.orderBy( ) 


 

entitySelection.orderBy ( criteria ) -> Result 
Parameter Type   Description
criteria  Text, Collection in Text: attribute path(s) and sorting instruction(s) for the entity selection
Collection: collection of criteria objects
Result  EntitySelection in New entity selection in the specified order

The entitySelection.orderBy( ) method returns a new ordered entity selection containing all entities of the entity selection in the order specified by criteria.

Notes:

You must use the criteria parameter to define how the entities must be sorted. Two syntaxes are supported for this parameter:

  • criteria is of text type (formula): In this case, criteria contains a formula made of 1 to x attribute paths and (optionally) sort orders, separated by commas. The formula syntax is:
    "attributePath1 {desc or asc}, attributePath2 {desc or asc},..."

    The order in which the attributes are passed determines the sorting priority of the entities. By default, attributes are sorted in ascending order. You can set the sort order of a property in the criteria string, separated from the property path by a single space: pass "asc" to sort in ascending order or "desc" in descending order.
  • criteria is of collection type: in this case, each element of the collection contains an object structured in the following way:
    {
        "propertyPath": string,
        "descending": boolean
    }

    By default, attributes are sorted in ascending order ("descending" is false).
    You can add as many objects in the criteria collection as necessary.

Note: Null values are evaluated as less than other values.

Example  

  // order by formula
 $sortedEntitySelection:=$entitySelection.orderBy("firstName asc, salary desc")
 $sortedEntitySelection:=$entitySelection.orderBy("firstName")
 
  // order by collection with or without sort orders
 $orderColl:=New collection
 $orderColl.push(New object("propertyPath";"firstName";"descending";False))
 $orderColl.push(New object("propertyPath";"salary";"descending";True))
 $sortedEntitySelection:=$entitySelection.orderBy($orderColl)
 
 $orderColl:=New collection
 $orderColl.push(New object("propertyPath";"manager.lastName"))
 $orderColl.push(New object("propertyPath";"salary"))
 $sortedEntitySelection:=$entitySelection.orderBy($orderColl)



See also 

entitySelection.orderByFormula( )
entitySelection.query( )
ORDER BY
ORDER BY ATTRIBUTE
QUERY BY ATTRIBUTE

 
PROPERTIES 

Product: 4D
Theme: ORDA - EntitySelection

 
PAGE CONTENTS 
 
HISTORY 

Created: 4D v17

 
ARTICLE USAGE

4D Language Reference ( 4D v19)
4D Language Reference ( 4D v19.1)
4D Language Reference ( 4D v19.4)
4D Language Reference ( 4D v19.5)
4D Language Reference ( 4D v19.6)
4D Language Reference ( 4D v19.7)
4D Language Reference ( 4D v19.8)