setSortFn( ) method
- Last Updated: January 17, 2024
- 3 minute read
- OpenEdge
- Version 12.8
- Documentation
Specifies or clears a user-defined sort function with which to automatically sort the
record objects for a table reference after you have set its autoSort
property to true (the default).
This method enables or disables automatic sorting based on a sort function only for
supported JSDO operations. See the description of the autoSort property for
more information.
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.
- 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:
When the JSDO invokes an automatic sort, and a sort function is set using this method, the sort uses this function to determine the sort order for every pair of records that it tests as it iterates through the record objects of the specified table reference.
If you set the funcRef parameter to null, the method
clears any sort function definition. Automatic sorting for the table reference can then
occur only if there are one or more existing sort fields set using the
setSortFields( ) method.
string fields in funcRef are case sensitive according to JavaScript rules and ignore the setting
of the caseSensitive property.setSortFields( ) in addition to using this method to set a sort function,
the sort function takes precedence.Examples
In the following code fragment, assuming the autoSort property is set to
true on dsCustomer.eCustomer (the default), after the
fill( ) method initializes JSDO memory, the record objects for
eCustomer are automatically sorted using the results of the external
user-defined function, sortOnNameCSensitive( ), whose reference is passed
to the setSortFn( ) method. In this case, the function compares the
case-sensitive values of the Name fields from each pair of
eCustomer record objects selected by the sort. At a later point, the
foreach( ) method then loops through these record objects, starting with
the first record in eCustomer sort order:
|
If you want to compare the Name field in this function using a
case-insensitive test, you can use the JavaScript toUpperCase( ) function
in the user-defined function. For example, in sortOnNameCInsensitive( ), as
follows:
|
See also:
autoSort property, caseSensitive property, setSortFields( ) method, sort( ) method