table rearrange ... columns

Prev Next

Function Names

table rearrange columns, table rearrange existing columns

Description

This function rearranges and rearranges the columns specified according to the order provided in the 2nd function parameter. All remaining columns will be deleted.

Call as: procedure

Restrictions

Indirect parameter passing is disabled

Parameter count

2

Parameters

No.TypeDescription
1.
input
string Name of existing table

2
input
table columns Existing columns

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

  • Any number of header names and column numbers may be specified
  • Appliable to table rearrange existing columns: No exceptions are asserted if header names are missing or column numbers are out of range.
  • Repeating the same columns (e.g. with intention to duplicate them) is not allowed.

Exceptions

Table not found
Header name not found

Examples

  table initialize ( table, { { First Name, "Middle Init.",    Last Name, "Street",      "Town" },
                  { Jane,       "E.",              Archer,    "1. Main St.", "Miami", "Comments" } } );

  echo("Original table: ", table max width(table), " columns. __________________ ");
  table list( table );

  table copy table (table, t1 );
  table rearrange columns(t1, { 2, First Name, -1 }); // Last Name, First Name, Town
  echo("Names only: ", table max width(t1), " columns. __________________ ");
  table list( t1 );

  table copy table (table, t1 );
  table rearrange existing columns(t1, { 5, 2, First Name, Phone }); // Comments column, last name, first name, No phone Nr.
  echo("Names only: ", table max width(t1), " columns. __________________ ");
  table list( t1 );

Output

Original table: 6 columns. __________________
    0 : First Name | Middle Init. | Last Name | Street      | Town  |         
    1 : Jane       | E.           | Archer    | 1. Main St. | Miami | Comments

Names only: 6 columns. __________________
    0 : Last Name | First Name | Town  | Middle Init. | Street      |         
    1 : Archer    | Jane       | Miami | E.           | 1. Main St. | Comments

Names only: 6 columns. __________________
    0 :          | Last Name | First Name | Middle Init. | Street      | Town
    1 : Comments | Archer    | Jane       | E.           | 1. Main St. | Miami

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

See also

table keep columns
table sort columns