ONLINE HELP
 WINDEVWEBDEV AND WINDEV MOBILE

Help / WLanguage / WLanguage functions / Controls, pages and windows / Table functions
  • Use conditions
  • Sorting a Table or TreeView Table control based on a data file
  • Managing a sorted Table or TreeView Table control
  • Sort on a calculated column
  • Programmatically loop through Table or TreeView Table controls
  • Performing a sort according to the ASCII value
WINDEV
WindowsLinuxUniversal Windows 10 AppJavaReports and QueriesUser code (UMC)
WEBDEV
WindowsLinuxPHPWEBDEV - Browser code
WINDEV Mobile
AndroidAndroid Widget iPhone/iPadIOS WidgetApple WatchMac CatalystUniversal Windows 10 App
Others
Stored procedures
Sorts a Table or TreeView Table control on one or more columns (lexicographical sort).
Remark: When a control is sorted by <Table>.Sort, the images used to identify the sort direction are not displayed in the columns.
Example
// Sort "COL_Designation" and "COL_Price" columns in "TABLE_Product"
// "COL_Designation" is sorted in ascending order
// "COL_Price" is sorted in descending order
TABLE_Product.Sort("COL_Designation", "-COL_Price")
Syntax

Sorting a Table or TreeView Table control on one or more columns identified by their name Hide the details

<Result> = <Table control>.Sort(<Column 1> [, <Column 2> [... [, <Column N>]]])
<Result>: Boolean
  • True if the sort was performed,
  • False otherwise.
<Table control>: Control name
Name of the control to be used. This control can correspond to:
  • a Table control.
  • a TreeView Table control.
<Column 1>: Character string
Name of first column to sort (up to 16 columns). This parameter has the following format:
"[<Direction>]<Column name>"

where:
  • <Direction> (character) indicates the sort direction:
    • "+": ascending sort (by default),
    • "-": descending sort.
  • <Column name> (character string): name of column to sort.
<Column 2>: Optional character string
Name of the second column to sort (up to 16 columns). This parameter has the following format:
"[<Direction>]<Column name>"

where:
  • <Direction> (character) indicates the sort direction:
    • "+": ascending sort (by default),
    • "-": descending sort.
  • <Column name> (character string): name of column to sort.
<Column N>: Optional character string
Name of Nth column to sort (up to 16 columns). This parameter has the following format:
"[<Direction>]<Column name>"

where:
  • <Direction> (character) indicates the sort direction:
    • "+": ascending sort (by default),
    • "-": descending sort.
  • <Column name> (character string): name of column to sort.

Canceling a sort that was previously defined on a Table or TreeView Table control populated programmatically Hide the details

<Result> = <Table control>.Sort(<False>)
<Result>: Boolean
  • True if the sort was canceled,
  • False if a problem occurred.
<Table control>: Control name
Name of the control to be used. This control can correspond to:
  • a Table control populated programmatically.
  • a TreeView Table control populated programmatically.
<False>: Constant
False: Keyword used to remove a sort previously defined on a Table or TreeView Table control populated programmatically.
Remarks

Use conditions

<Table>.Sort can be used on:
  • a Table or TreeView Table control populated programmatically.
  • a Table or TreeView Table control based on a data file with automatic iteration ("Browse automatically" option in the "Content" tab of the control description). In this case, only one column is sorted.
  • a single-selection or multi-selection control.
    WEBDEV - Server codePHP Reminder: Multi-selection is not available for Table controls in classic mode.
WEBDEV - Server codePHP This function is available for Table controls in "Server" and "Server + AJAX" mode, and for TreeView Table controls.
WEBDEV - Browser code This function is available for Table controls in "Browser" mode only.
WEBDEV - Browser code The TreeView Table control is not available.

Sorting a Table or TreeView Table control based on a data file

A Table or TreeView Table control based on a data file will be sorted according to the first specified column (syntax 1 and 2). Caution: the column used for the sort must be linked to a key item in the data file used to browse the control.
Tip: To sort a Table or TreeView Table control based on a data file with several columns, use a composite key and the BrowsedItem property:
TableName..BrowsedItem = NAMECOMPOSITEKEY
To cancel a sort in a Table or TreeView Table control based on a data file, simply assign an empty string to the BrowsedItem property.

Managing a sorted Table or TreeView Table control

Reminder: <Table>.SortedColumn returns the list of sorted columns.

Sort on a calculated column

It is not recommended to use <Table>.Sort on calculated columns. These columns are calculated when each row is displayed.
A sort defined with <Table>.Sort on a calculated column will be valid only for the rows already displayed.

Programmatically loop through Table or TreeView Table controls

<Table>.Sort has no effect on controls looped through programmatically.

Performing a sort according to the ASCII value

A memory area allows you to perform a sort according to the ASCII value
Example:
MemCreate("MZ")
MemAdd("ZM", "abc", "abc")
MemAdd("ZM", "ZZZ", "ZZZ")
MemAdd("ZM", "zbc", "zbc")
MemAdd("MZ", "ééébc", "ééébc")
MemAdd("ZM", "AB", "AB")
MemAdd("ZM", "CD", "CD")
MemAdd("MZ", "çabc", "çabc")
MemAdd("ZM", "bbc", "bbc")
MemSort("MZ")
i is int
MemFirst("MZ")
WHILE NOT MemOut("MZ")
i = MemCurrent("ZM")
Trace(MemRetrieve("MZ", i)) // Display in ASCII order
MemNext("MZ")
END
Component: wd290obj.dll
Minimum version required
  • Version 23
This page is also available for…
Comments
Click [Add] to post a comment

Last update: 06/20/2023

Send a report | Local help