table rearrange selected rows

Prev Next

Function Names

table rearrange selected rows

Description

This function rearranges selected rows in the table in order to put them together into one block so they are no longer scattered across the table. The ordering of the selected rows will not change, but you can change it (before or) afterwards with table sort selected rows(). This function extracts a column from the table and places the values in the set from the selected rows where the calculated expression returns true. All blank or non-existing entries will be translated to blank strings. Automatic type conversion (e.g. numbers to numerals) can be adjusted with the table configure() function.

Call as: procedure

Restrictions

Indirect parameter passing is disabled
This function provides a table context for partial table specifications with table name and row number for selected function parameters

Parameter count

3

Parameters

No.TypeDescription
1.
input
string Name of existing table

2.
code
expression
:string
Expression to select rows

Specify the conditions or rules to select the rows. See expressions to select rows.
The table context for partial table specifications is available for referencing just the columns easily. Example: [Year]>=2022.
Attention: Comparison operators = and <> (instead of == and !=) may hijack the next function parameters for its own use as additional comparison operands, e.g. a[]=1,3,5. As long this comparison is not made in the last function parameter, then put parentheses around them, e.g. ... , (a[]=1,3,5), ....

3.
input
string Relocation destination

Use one of the following values:

top All selected rows will be relocated to the top of the table, with 1st row just below the header row.
bottom All selected rows will be relocated to the top of the table
first match All selected rows will be relocated to the 1st row where the selection applies
last match All selected rows will be relocated to the last row where the selection applies

Examples

       table initialize( animals,
               { { Animal, Leg Count, Comment },
                 { ant, 6 }, { rat, 4 }, { octopus, 8 }, { centipede, 100 }, { parakeet, 2 },
                 { tick, 8 }, { orang utan, 2 or 4 }, { human, 2 }, { lobster, 8 }, { snake, 0 }, { dog, 4 },
                 { cat, 4 }, { kangaroo, 2 or 4 }, { fly, 6 }, { alien, 3 }, { worm, 0 }, { emu, 2 } }  );

       table initialize( lookup, {
                 { Condition,                  Todo },
                 { "[Leg Count] = '*or*'",     "[Comment] = 'Leg count probably unclear'" },
                 { "[Leg Count] > 6",          "[Comment] = 'Many legs'" },
                 { "[Animal] = rat",           "[Animal] = 'mouse'; [Comment] += 'not a rat'" },
                 { "true",                     "[Animal] = ![Animal]" } } ); // Upper case O ALL

       table manipulate( animals, lookup, Condition, Todo );
       table list( animals );

Output

    0 : Animal     | Leg Count | Comment                   
    1 : Ant        | 6         |                           
    2 : Mouse      | 4         | not a rat                 
    3 : Octopus    | 8         | Many legs                 
    4 : Centipede  | 100       | Many legs                 
    5 : Parakeet   | 2         |                           
    6 : Tick       | 8         | Many legs                 
    7 : Orang utan | 2 or 4    | Leg count probably unclear
    8 : Human      | 2         |                           
    9 : Lobster    | 8         | Many legs                 
   10 : Snake      | 0         |                           
   11 : Dog        | 4         |                           
   12 : Cat        | 4         |                           
   13 : Kangaroo   | 2 or 4    | Leg count probably unclear
   14 : Fly        | 6         |                           
   15 : Alien      | 3         |                           
   16 : Worm       | 0         |                           
   17 : Emu        | 2         |                           

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

See also

table sort rows
table sort selected rows