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().
  4. An Array Table: This is an in-memory table that references a two-dimensional array.

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.
addIndex Adds an index to the specified column.
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.
getColNum Gets the index of a table column header.
getRowByKey Searches a column for the specified key value.
getRowHeader Gets a table row header.
getRowNum Gets the index of a table row header.
getValueByKey Searches a column for the specified key value, and returns one or more values from the matching row.
hasIndex Returns the index type of the specified column if it has an index, otherwise 0.
moveCol Moves a column to a new index.
moveRow Moves a row to a new index.
removeIndex Removes an index from the specified column
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 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.addIndex()

addIndex( Variant keyCol , int indexType = Table.IndexType.Unordered )

Parameters

keyCol A column name or number
indexType The type of index desired. Can be either Table.IndexType.Unordered or Table.IndexType.Ordered. Generally the default unordered value is sufficient. Table.IndexType.Ordered can be useful if you are querying the table with Table.query() with a WHERE filter that uses a >, <, >=, or <= comparison on the column.

Description

Adds an index to the specified column.

An index can significantly improve the performance of the following operations:
  • Using the Table.getRowByKey() method with the indexed column
  • Using the Table.getValueByKey() method with the indexed column
  • Finding a value from the indexed column in a query (e.g. WHERE IndexedCol = SomeValue
An index can significantly slow performance to operations that change the table. If a table changes frequently during the model run, an index is not recommended. You can only add an index to a column in a Bundle table.
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.getColNum()

int getColNum( string colHeader )

Parameters

colHeader The column header.

Returns

int The index of the column header.

Description

Gets the index of a table column header.

int col = table.getColNum("Orders");

Returns 0 if the column header doesn't exist.

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

Table.getRowByKey()

int getRowByKey( Variant key , Variant keyCol = nullvar )

Parameters

key The value to use as the key
keyCol The column to search for the key value.

Returns

int The row number containing the key value in the specified column. If no match was found, returns 0.

Description

Searches a column for the specified key value.

If the keyCol is not specified, the first indexed column in the table will be searched. If there is no indexed column, the first column (column 1) will be searched.
If the column to search has an index, then the index will be used to look up the correct row, rather than searching row by row.
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.getRowNum()

int getRowNum( string rowHeader )

Parameters

rowHeader The row header.

Returns

int The index of the row header.

Description

Gets the index of a table row header.

int row = table.getRowNum("Type");

Returns 0 if the row header doesn't exist.

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

Table.getValueByKey()

Variant getValueByKey( Variant key , Variant valueCol , Variant keyCol = nullvar )

Parameters

key The value to use as the key
valueCol A column (name or number) to retrieve data from.
keyCol The column to search for the key value.

Returns

Variant The value in the valueCol in the matching row.

Description

Searches a column for the specified key value, and returns one or more values from the matching row.

If the keyCol is not specified, the first indexed column in the table will be searched. If there is no indexed column, the first column (column 1) will be searched.
If the column to search has an index, then the index will be used to look up the correct row, rather than searching row by row.
Once the matching row is found, the value in valueCol on that row is retrieved. If valueCol is an array, the values from each specified column will be retrieved, and returned as an array.
Do no remove, this fixes the anchor on doc.flexsim.com

Table.hasIndex()

int hasIndex( Variant keyCol )

Parameters

keyCol A column name or number

Returns

int If the specified column has an index, returns either Table.IndexType.Ordered or Table.IndexType.Unordered.

Description

Returns the index type of the specified column if it has an index, otherwise 0.

An index can be added using the Table.addIndex() method.
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.removeIndex()

removeIndex( Variant keyCol )

Parameters

keyCol A column name or number.

Description

Removes an index from the specified column

An index can be added using the Table.addIndex() method. If the specified column does not have an index, this method does nothing.
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 )
Table( treenode node )
Table( Array array )
Table( Variant value )

Parameters

name The name of a global table.
node A table-like treenode. The node should either have Bundle data, or have table-structured subnodes.
value A global table name, treenode, or array.
array A two-dimensional array. The first dimension spans the rows whereas the second dimension spans the columns. For example, you could get the result of a call to Storage.System. querySlots(), and construct a Table based on that result.

Description

Creates a reference to a table.

Table parts = Table("Parts");
int partCount = 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;

An exception will be thrown if the name of a row or column that does not exist is specified. To check that a row or columns with a certain name exists use Table.getColNum() or Table.getRowNum().

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 = Table("Data");
Table labelTable = current.labels["TableData"];