table sort columns

Prev Next

Function Names

table sort columns

Description

This functions sorts the columns in the table. If not specified otherwise, the header row will serve as sorting base. All table rows are included in the sorting process.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

1-5

Parameters

No.TypeDescription
1.
input
string Name of existing table

Opt. 2
input
table columns Column to mark begin of sorting range

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • One header name or column numbers may be specified

Default value: All columns will be sorted
Opt. 3
input
table columns Column to mark end of sorting range

See table columns as function parameters for general ruling for this parameter.
Specific rules apply for this function:

  • One header name or column numbers may be specified

No sorting takes place if the ending column lies before or over the starting column.

Default value: All remainign columns will be sorted
Opt. 4
input
string Sorting Option

See sorting options for available values.

Default value: alphabetic
Opt. 5
input
numeral Row number

Specify a different row number if the data in a specific row shall server as a base for sorting.

Default value: 0 (header row)

Exceptions

Table not found
Header name not found

Examples

  table initialize ( t,
  { {  Name, Town, Street, Phone, Gender, Country, Province, Favorite Pet },
    {  Dan,  La Spezia,  Main St., None, M, Italy, Liguria, Toad },
    {  Jane, Miami, Hill St., None, F, USA,  Florida, Alligator } } );


  echo("Original table:");
  table list( t );


  table copy table (t, t1 );

  echo("Sort all columns by header name except 1st and last one:");
  table sort columns( t, Town, -2 );
  table list ( t );

  echo("Sort all columns Z-A by Row 2:");
  table sort columns( t, Name, -1, alphabetic down, 2 );
  table list ( t );

Output

Original table:
    0 : Name | Town      | Street   | Phone | Gender | Country | Province | Favorite Pet
    1 : Dan  | La Spezia | Main St. | None  | M      | Italy   | Liguria  | Toad        
    2 : Jane | Miami     | Hill St. | None  | F      | USA     | Florida  | Alligator   

Sort all columns by header name except 1st and last one:
    0 : Name | Country | Gender | Phone | Province | Street   | Town      | Favorite Pet
    1 : Dan  | Italy   | M      | None  | Liguria  | Main St. | La Spezia | Toad        
    2 : Jane | USA     | F      | None  | Florida  | Hill St. | Miami     | Alligator   

Sort all columns Z-A by Row 2:
    0 : Country | Phone | Town      | Name | Street   | Province | Gender | Favorite Pet
    1 : Italy   | None  | La Spezia | Dan  | Main St. | Liguria  | M      | Toad        
    2 : USA     | None  | Miami     | Jane | Hill St. | Florida  | F      | Alligator   

Try it yourself: Open LIB_Function_table_sort_columns.b4p in B4P_Examples.zip. Decompress before use.

See also

table rearrange columns
table sort rows