new Table(arg1, arg2)
A Table - this wraps up the raw JSON attribute data and makes it easier to work with data tables. Tables can be created by passing in the an attribute value, or they can be created based on result sets from existing tables. Can also use ANARKCOREDATA#getWorkspaceTableByName
Parameters:
| Name | Type | Description |
|---|---|---|
| arg1 | object | Either the raw table attribute value or the table schema (columns) definition. |
| arg2 | object | If arg1 is the raw table value then this argument should be omitted. If arg1 is the table schema definition then arg2 must be the table rows. |
Methods
-
createIndex(columnName)
-
Creates an index on a specified column, which allows for the fast lookup of rows that match values in the specified column.
Parameters:
Name Type Description columnName string The name of the column to index. -
filterRows(matchFunction) → {Array.<Row>}
-
Filter rows based on a custom function that is passed in.
Parameters:
Name Type Description matchFunction function The row matching function. The function should take a row as its argument and return true if the row matches or false if the row does not match. Returns:
Array.<Row> An array of rows that meet the criteria of matchFunction. -
forEachFilteredRow(filterFunc, actionFunc)
-
Uses a function to filter rows and then executes a function for every filtered row.
Parameters:
Name Type Description filterFunc function The filtering function to execute. The function should take the rowIndex and the row as its arguments. Pass null for this parameter to use no filtering. actionFunc function The function to execute on each filtered row. The function should take the rowIndex and the row as its arguments. -
forEachRow(func)
-
Executes a function once for every row in the table.
Parameters:
Name Type Description func function The function to execute. The function should take the rowIndex and the row as its arguments. -
getCellValue(rowIndex, columnIndex) → {object}
-
Get a cell value by row index and column index.
Parameters:
Name Type Description rowIndex integer The row index. columnIndex integer The column index. Returns:
object The cell value. -
getCellValueByName(rowIndex, columnName) → {object}
-
Get a cell value by row index and column name.
Parameters:
Name Type Description rowIndex integer The row index. columnName string The column name. Returns:
object The cell value. -
getColumnName(columnIndex) → {string}
-
Get a column name by column index.
Parameters:
Name Type Description columnIndex integer The column index. Returns:
string The column name. -
getColumns() → {Array.<Column>}
-
Get the table column (schema) information.
Returns:
Array.<Column> -
getIndexedRows(columnName, indexValue) → {Array.<Row>}
-
Gets the rows that exactly match a value in an indexed column. An index must exist on the column before using this.
Parameters:
Name Type Description columnName string The indexed column name. indexValue string The search string. Returns:
Array.<Row> An array of rows representing the unique index keys. -
getIndexValues(columnName) → {Array.<string>}
-
Gets the unique key values of a column index. This can be used to get all unique values in a column.
Parameters:
Name Type Description columnName string The indexed column name. Returns:
Array.<string> An array of strings representing the unique index keys. -
getRows() → {Array.<Row>}
-
Get all table rows.
Returns:
Array.<Row> The cell value. -
sortAscending(columnIndex) → {Table}
-
Sorts the table according to the data in the column specified by the columnIndex parameter, in ascending order.
Parameters:
Name Type Description columnIndex number The index of the column to sort on. Returns:
Table A new table object with the rows sorted. -
sortAscendingByColumnName(columnName) → {Table}
-
Sorts the table according to the data in the column specified by the columnName parameter, in ascending order.
Parameters:
Name Type Description columnName number The name of the column to sort on. Returns:
Table A new table object with the rows sorted. -
sortCustom(sortFunction) → {Table}
-
Sorts the table using the provided sortFunction. This does not sort the table in place - it creates a new table.
Parameters:
Name Type Description sortFunction function The custom sort function - takes parameters a and b that represent table rows. Returns:
Table A new table object with the rows sorted. -
sortDescending(columnIndex) → {Table}
-
Sorts the table according to the data in the column specified by the columnIndex parameter, in descending order.
Parameters:
Name Type Description columnIndex number The index of the column to sort on. Returns:
Table A new table object with the rows sorted. -
sortDescendingByColumnName(columnName) → {Table}
-
Sorts the table according to the data in the column specified by the columnName parameter, in descending order.
Parameters:
Name Type Description columnName number The name of the column to sort on. Returns:
Table A new table object with the rows sorted.