BomTable

new BomTable()

BomTable to abstract html/pdf bom table data for easy manipulation and front end presentation
For useful helper functions, see BomFunctions

Methods

addColumn(name, func, index)

Inserts a new column into the table, with automatically generated values generated based on evalFunction Requires Cad Data to be either mapped to table or bom to be built on Cad Data

Parameters:
Name Type Argument Default Description
name string Name of the new column
func evalFunction The function to which each cell of new column will evaluate to
index integer optional  -1 The location of the new column, default end of the table
Examples
// add new column to end of the table
bomTable.addColumn('Quantity', getOccurrenceCount);
// add new column to the front of table
bomTable.addColumn('Component Name', getComponentName, 0);

addFooter(input)

Method to create a footer row at end of table. with each cell set to input

Parameters:
Name Type Description
input string | number The value to set each cell to

addRow(input, index)

Inserts a new row into the table

Parameters:
Name Type Argument Default Description
input Array.<columnIndex> The input for each column of the new row
index integer optional  -1 The location of the new row, default end of the table
Examples
// add a row of strings to end of a 4 column table
bomTable.addRow(['fee', 'fie', 'fo', 'fum'])
// add row at start that doesn't tie into cad data of 3 column table with columns ['name', 'quantity', 'price']
bomTable.addRow(['glue', 4, 25], 0)

clearOldGroup(name)

Method to remove group

Parameters:
Name Type Description
name groupName group to remove

createGroupByFilter(name, search) → {Array.<integer>}

Method to create a group by searching rows for conditions

Parameters:
Name Type Description
name groupName
search Array.<search> for each row to see if it should be added to group
Returns:
Array.<integer> the row indexes that were added to the group
Example
// create group 'quantity over 1' by searching for column 'quantity' over 1
bomTable.createGroupByFilter('quantity over 1', [['quantity]])

createGroupByIndexes(name, indexes) → {Array.<integer>}

Method to create a group by row indexes

Parameters:
Name Type Description
name groupName Name of group
indexes Array.<integer> row indexes to associate with group
Returns:
Array.<integer> the row indexes that were added to the group
Example
// create group 1 with rows 0, 1, 2
bomTable.createGroupByIndexes(1, [0, 1, 2])

deleteColumn(column)

Delete an entire row and its cells from a table

Parameters:
Name Type Description
column columnIndex Either the name/index of the column to delete

deleteRow(index)

Delete a row from the table

Parameters:
Name Type Description
index integer Index of row delete

getCell(colIndex, rowIndex)

Get the contents of a cell

Parameters:
Name Type Description
colIndex columnIndex The desired column name/index
rowIndex integer The desired row index

getColumnIndex(name)

Get the index of a column given a name

Parameters:
Name Type Description
name string Name of the column

getColumnName(index)

Get the name of a column at an index

Parameters:
Name Type Description
index integer The index of the column

getIndexesFromGroup(name) → {Array.<integer>}

Get the indexes from a group

Parameters:
Name Type Description
name groupName Name of group desired
Returns:
Array.<integer> Row Indexes from group

getIndexFromOccurrence(occId)

Get the index of the row matching the Occurrence Id provided. Throws exception if no index matches the given Occurrence

Parameters:
Name Type Description
occId integer The Id of the Occurrence

getNumberColumns() → {integer}

Get the number of columns in table

Returns:
integer Column count

getNumberRows() → {integer}

Get the number of rows in table

Returns:
integer Row count

getOccurrenceIdsFromIndex(index)

Get Occurrences associated with a row

Parameters:
Name Type Description
index integer The desired row index

getOccurrencesFromGroup(name) → {Array.<integer>}

Get the Occurrences associated with a group

Parameters:
Name Type Description
name groupName Name of group desired
Returns:
Array.<integer> Occurrences from rows in group

orderRowsBy(column, opt)

Order rows of table by specific column

Parameters:
Name Type Description
column columnIndex The column name/index you wish to order by
opt integer 1: ascending order, -1: descending order

searchTableForIndexes(search)

Get the rows that match a search array, where each element of the array is a tuple with the column and its requirements to match

Parameters:
Name Type Description
search Array.<search> The search Array
Example
// find a rows that have Occurrence Quantity over 1, using searchQuantityOverOne
var rowIndexes = bomTable.searchTableForIndexes([['quantity', searchQuantityOverOne]])

searchTableForOccurrences(search) → {Array.<integer>}

Get Occurrences that match search parameters

Parameters:
Name Type Description
search Array.<search> The search Array
Returns:
Array.<integer> The Occurrences associated with the search
Example
// gets Occs that where rows have quantity over 1 in 'quantity' column
var occs = bomTable.searchTableForOccurrences([['quantity', searchForQuantityOverOne]]);

swapRow(currentIndex, newIndex)

Swaps two rows in the table. Moves first row to second, vice versa.

Parameters:
Name Type Description
currentIndex integer The first row
newIndex integer The second row