SetSort

Description

Specifies sort criteria for a Web DataWindow client control.

Applies to

Web DataWindow client control

Syntax

number objdwcontrol.SetSort ( string format ) 

Argument

Description

objdwcontrol

A reference to a Web DataWindow client control.

format

A string whose value is valid sort criteria for the DataWindow (see Usage). The expression includes column names or numbers.

A column number must be preceded by a pound sign (#).

Returns

Returns 1 if it succeeds and -1 if an error occurs.

Usage

A DataWindow object can have sort criteria specified as part of its definition. SetSort overrides the definition, providing new sort criteria for the DataWindow. However, it does not actually sort the rows. Call the Sort method to perform the actual sorting.

The sort criteria for a column have one of the forms shown in the following table, depending on whether you specify the column by name or number.

Table 12-3: Examples for specifying sort order

Syntax for sort order

Examples

columnname order

"emp_lname A"

"emp_lname asc, dept_id desc"

# columnnumber order

"#3 A"

The following table shows the recognized values for order. These values are case insensitive. For example, as, s, AS, or S all specify a case-sensitive sort in ascending order.

Table 12-4: Recognized values for sort order

Order value

Resulting sort order

a, asc, ascending, ai, i

Case-insensitive ascending

d, desc, descending, di

Case-insensitive descending

as, s

Case-sensitive ascending

ds

Case-sensitive descending

If you omit order or specify an unrecognized string, the sort is performed in ascending order and is case insensitive. You can specify secondary sorting by specifying criteria for additional columns in the format string. Separate each column specification with a comma.

Examples

Example 1

This function on a client-side button sets the sort criteria for objdwSort so that dwSort is sorted in ascending order by the values in the column selected by the user. Since ascending order is the default, the + "A" in the call to SetSort could be omitted:

function btn_ClientSort_onclick() {
   if (!columnSelected) {
      alert("Select a column on which to sort!");
      return;
   }
   objdwSort.SetSort(Form1.sle_colname.value + "A");
   objdwSort.Sort();
}

The button is defined in the JavaScript for the form:

<INPUT language="javascript" id="btn_ClientSort" style="Z-INDEX: 101; LEFT: 40px; WIDTH: 96px; POSITION: absolute; TOP: 312px; HEIGHT: 24px"				onclick="return btn_ClientSort_onclick()" type="button" value="Sort from Client">