sort( ) method
- Last Updated: March 30, 2020
- 3 minute read
- OpenEdge
- Version 12.2
- Documentation
Sorts the existing record objects for a table reference in JSDO memory using either specified sort fields or a specified user-defined sort function.
Return type: null
Applies to: progress.data.JSDO class, table reference property (JSDO class)
Syntax
|
- jsdo-ref
- A reference to the JSDO. You can call the method on jsdo-ref if the JSDO has only a single table reference.
- table-ref
- A table reference on the JSDO.
- sort-fields
- An array of
stringvalues set to the names of record fields on which to sort the record objects, with an optional indication of the sort order for each field. This array can have the following syntax: - funcRef
- A reference to a JavaScript sort function that compares two record
objects for the sort and returns a
numbervalue. This function must have following signature:
sort( ) method executes in JavaScript on the
client side, sorting a large set of record objects can take a significant amount of time and
make the UI appear to be locked. You might set a wait or progress indicator just prior to
invoking the sort to alert the user that the app is working.Examples
In the following code fragment, the fill( ) method initializes JSDO memory with eCustomer record objects from the server in order of the table primary key (the
default). The sort( ) method later sorts the record
objects for eCustomer by the Country field ascending, then by the State
field within Country ascending, then by the Balance field within State
descending. The foreach( ) function then loops through
these record objects in the new eCustomer sort order:
|
In the following code fragment, the fill( ) method initializes JSDO memory with eCustomer record objects from the server in order of the table primary key (the
default). The sort( ) method later sorts the record
objects for eCustomer using the results of an inline
function definition, which in this case compares the case-sensitive values of the Name fields from each pair of eCustomer record objects selected by the sort. The foreach( ) method then loops through these record objects in the new eCustomer sort order:
|
If you want to compare the Name fields using a case-insensitive test, you
can use the JavaScript toUpperCase( ) function in the inline function
definition, as follows:
|
See also:
autoSort property, caseSensitive property, setSortFields( ) method, setSortFn( ) method