Table of Contents

Table of Contents

FlexScript Class - Table

Table

Description

A class that represents a table structure.

A Table contains methods and properties associated with manipulating table data in FlexSim. A Table may be one of the following:

  1. A Tree Table: This is a table whose data is defined in the tree structure. This consists of a root node with one or more subnodes, each representing a row in the table. Subnodes of each row represent cells in the table.
  2. A Bundle Table: This is a table whose data is defined by a bundle node. This consists of a node in the tree that contains bundle data.
  3. A Query Result Table: This is a read-only in-memory table that contains the result of a call to Table.query().

Bundle and tree tables can be stored anywhere in the model tree. Often they are stored as global tables, or on object labels.

Properties

numCols The number of columns in the table.
numRows The number of rows in the table.

Methods

addCol Adds a column to the table.
addRow Adds a row to the table.
cell Returns a specific table cell.
clear Sets all cells to empty values.
clone Creates an array copy of the table.
cloneTo Copies all values from this table to the target table, returning the target table.
deleteCol Deletes a table column.
deleteRow Deletes a table row.
executeCell Executes the text on the cell as FlexScript.
getColHeader Gets a table column header.
getRowHeader Gets a table row header.
moveCol Moves a column to a new index.
moveRow Moves a row to a new index.
setColHeader Renames a column header.
setRowHeader Renames a row header.
setSize Resizes the table.
sort Sorts table columns.
swapCols Swaps indexes of the two columns.
swapRows Swaps indexes of the two rows.

Constructor

Table Creates a reference to a global table.

Static Methods

query Executes an SQL query, returning the result as a Table.

Operators

[] Gets or sets the value of a table cell.
= Assigns a reference to a treenode to the Table object.

Details

Do no remove, this fixes the anchor on doc.flexsim.com

Table.numCols

readonly int numCols

Description

The number of columns in the table.

int columns = table.numCols; For bundles it is the number of fields.
Do no remove, this fixes the anchor on doc.flexsim.com

Table.numRows

readonly int numRows

Description

The number of rows in the table.

int rows = table.numRows; For bundles it is the number of entries.
Do no remove, this fixes the anchor on doc.flexsim.com

Table.addCol()

Table addCol( int col = 0 , int datatype = 0 )

Parameters

col The index at which to insert the column.
datatype The datatype of the new column.

Returns

Table The table.

Description

Adds a column to the table.

table.addCol(2);

If no column index is specified the column will be added at the end. If no datatype is specified the new column will copy the datatype of the previous column.

Do no remove, this fixes the anchor on doc.flexsim.com

Table.addRow()

Table addRow( int row = 0 , int datatype = 0 )

Parameters

row The index at which to insert the row.
datatype The datatype of the new row.

Returns

Table The table.

Description

Adds a row to the table.

table.addRow(2);

If no row index is specified the row will be added at the end. If no datatype is specified the cells will copy the datatype of the cells in the previous row.

Do no remove, this fixes the anchor on doc.flexsim.com

Table.cell()

treenode cell( Variant row , Variant col )

Parameters

row The row index.
col The column index.

Returns

treenode The cell's node in the tree.

Description

Returns a specific table cell.

table.cell(2,"Row 3").value = 4;

This will throw an exception for bundles.

Do no remove, this fixes the anchor on doc.flexsim.com

Table.clear()

Table clear( int recursive = 0 )

Parameters

recursive If set to 1, clear will be called on cells with bundle data, array data and on cells that have node tables.

Returns

Table The table.

Description

Sets all cells to empty values.


table.clear();
table.clear(1);

Number cells will be set to 0, string cells to an empty string, and pointer cells will be set to a null pointer.

Do no remove, this fixes the anchor on doc.flexsim.com

Table.clone()

Array clone( )

Returns

Array A copy of the table in an array.

Description

Creates an array copy of the table.


Array myArray = Table("Parts").clone();
      		
Do no remove, this fixes the anchor on doc.flexsim.com

Table.cloneTo()

Table cloneTo( Table target )

Parameters

target The target table. This must be a tree-bound table, such as a bundle or tree table.

Returns

Table The resulting table. This is the same table as the target.

Description

Copies all values from this table to the target table, returning the target table.

Table.query("SELECT * FROM Customers ORDER BY Name").cloneTo(Table("QueryDump"));
Do no remove, this fixes the anchor on doc.flexsim.com

Table.deleteCol()

Table deleteCol( int col )

Parameters

col The index of the column to delete.

Returns

Table The table.

Description

Deletes a table column.

table.deleteCol(3);

Will throw an exception if no column is specified or the column doesn't exist.

Do no remove, this fixes the anchor on doc.flexsim.com

Table.deleteRow()

Table deleteRow( int row )

Parameters

row The index of the row to delete.

Returns

Table The table.

Description

Deletes a table row.

table.deleteRow(3);

Will throw an exception if no row is specified or the row doesn't exist.

Do no remove, this fixes the anchor on doc.flexsim.com

Table.executeCell()

Variant executeCell( Variant row , Variant col )

Parameters

row The row index.
col The column index.

Returns

Variant The return value of the executed function.

Description

Executes the text on the cell as FlexScript.

Variant result = table.executeCell(2, "Row 3");
Do no remove, this fixes the anchor on doc.flexsim.com

Table.getColHeader()

string getColHeader( int colNum )

Parameters

colNum The column index.

Returns

string The text in the column header.

Description

Gets a table column header.

string header = table.getColHeader(2);
Do no remove, this fixes the anchor on doc.flexsim.com

Table.getRowHeader()

string getRowHeader( int rowNum )

Parameters

rowNum The row index.

Returns

string The text in the row header.

Description

Gets a table row header.

string header = table.getRowHeader(2);
Do no remove, this fixes the anchor on doc.flexsim.com

Table.moveCol()

Table moveCol( int col , int newCol )

Parameters

col The index of the column to move.
newCol The index where the column will be moved.

Returns

Table The table.

Description

Moves a column to a new index.

table.moveCol(2, 5);
Do no remove, this fixes the anchor on doc.flexsim.com

Table.moveRow()

Table moveRow( int row , int newRow )

Parameters

row The index of the row to move.
newRow The index where the row will be moved.

Returns

Table The table.

Description

Moves a row to a new index.

table.moveRow(2, 5);
Do no remove, this fixes the anchor on doc.flexsim.com

Table.setColHeader()

Table setColHeader( int colNum , string name )

Parameters

colNum The column index.
name The new column header name.

Returns

Table The table.

Description

Renames a column header.

table.setColHeader(2, "Orders");
Do no remove, this fixes the anchor on doc.flexsim.com

Table.setRowHeader()

Table setRowHeader( int rowNum , string name )

Parameters

rowNum The row index.
name The new row header name.

Returns

Table The table.

Description

Renames a row header.

table.setRowHeader(2, "Order 2");
Do no remove, this fixes the anchor on doc.flexsim.com

Table.setSize()

Table setSize( int rows , int cols , int datatype = 0 , int overwrite = 0 )

Parameters

rows The new number of rows.
cols The new number of columns.
datatype The datatype of new cells.
overwrite If old cells should have their values reset.

Returns

Table The table.

Description

Resizes the table.

table.setSize(5, 3);
Do no remove, this fixes the anchor on doc.flexsim.com

Table.sort()

Table sort( Variant columns , Variant sortDirections = 0 )

Parameters

columns The column or columns to sort.
sortDirections The directions each column should be sorted. 0 is Descending and 1 is Ascending.

Returns

Table The table.

Description

Sorts table columns.

table.sort(1);table.sort([1, 2, 3], [1, 0, 1]);
Do no remove, this fixes the anchor on doc.flexsim.com

Table.swapCols()

Table swapCols( int col , int col2 )

Parameters

col The index of the first column.
col2 The index of the ssecond column.

Returns

Table The table.

Description

Swaps indexes of the two columns.

table.swapCols(2, 4);
Do no remove, this fixes the anchor on doc.flexsim.com

Table.swapRows()

Table swapRows( int row , int row2 )

Parameters

row The index of the first row.
row2 The index of the second row.

Returns

Table The table.

Description

Swaps indexes of the two rows.

table.swapRows(2, 4);
Do no remove, this fixes the anchor on doc.flexsim.com

Table Constructor

Table( string name )

Parameters

name The name of the global table.

Description

Creates a reference to a global table.

Table parts = Table("Parts");int numParts = Table("Parts")[3][4];
Do no remove, this fixes the anchor on doc.flexsim.com

Table.query()

static Table query( string queryStr , lambda p1 ... p9 = 0 )

Parameters

queryStr The sql query.
p1-p9 Only used if you include $ syntax in the query. This defines additional, dynamically evaluated parameters associated with the query. The value is a "lambda", a type that simply signifies that the parameter is evaluated as-needed, not immediately when the method is called. You will usually either pass a reference to a table node here, defining the table to query, or you will use the $iter() command in a FlexScript expression to dynamically determine the value of a cell in a "virtual table." If this parameter defines a table, it must be a tree-bound table or a direct reference to a node. In other words, it cannot be the result Table of another call to Table.query(), unless you clone that result to a tree-bound table with Table.cloneTo(). See Sql Query Examples for more information.

Returns

Table The resulting table. This is a read-only in-memory table (it is not stored on a node in the tree). Use Table.cloneTo() to copy the result to a tree-bound table.

Description

Executes an SQL query, returning the result as a Table.

Table result = Table.query("SELECT * FROM Customers ORDER BY Name");

See Sql Query Examples for more information.

Do no remove, this fixes the anchor on doc.flexsim.com

Table.operator []

Variant operator []( Variant index )

Parameters

index The index or name of a row or column.

Returns

Variant The variant held by the table cell. If the cell is a FlexScript node this returns the result of executing the code.

Description

Gets or sets the value of a table cell.

Variant value = table[2]["Orders"];table[2]["Orders"] = 5;
Do no remove, this fixes the anchor on doc.flexsim.com

Table.operator =

Table operator =( treenode node )

Parameters

node The node holding a table.

Returns

Table The table.

Description

Assigns a reference to a treenode to the Table object.

Table table = reftable(1);