- Table Operations
- Reading All Rows in a Table
- Setting Cell Values in a Table
- Handling Row Clicks
- Reading a Column by Name
- Highlighting Cells
- Appending a Row to a Table
- Table Validation and Calculations
- Example: Checking Aggregate Values
- Example: Multi-Column Validation
- Writing Table Selectors
- Table Selectors
- Column Selectors
- Known Limitations
- “Attach Autocomplete” brick fills multiple cells when a value is selected
Table Operations
Reading All Rows in a Table
- Add the “Read AARI Table Field” brick
- Enter a selector for the field name of the table, e.g.,
#Table0
,#Table1
, etc. When you type in the selector, PixieBrix will highlight the table: - ⚠️ If you are using the brick in a Trigger, set the Root Mode of the brick to
Document
. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event
Setting Cell Values in a Table
- Add the “Set AARI Table Field Values” brick
- ⚠️ If you are using the brick in a Trigger, set the Root Mode of the brick to
Document
. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event
Handling Row Clicks
- Add a Click handler targeting the table field, e.g.,
#Table1 tbody tr
- Set the target mode to
root
. By setting the mode toroot
the trigger will pass along the row element, even if the use clicks on a cell or input within the row - Add the “Read AARI Table Field Row” brick and rename the output key to
row
- Leave the
rowSelector
blank and set the Root Mode toInherit
for the brick to read from the row that was clicked - When you click the row, the output of the brick with be available as an array at
@row.values
Reading a Column by Name
- Add the "Read AARI Table Field Column” brick
- Provide the table selector based on the field name of the table, e.g.,
#Table1
- Provide the column heading to read, e.g.,
Column 1
- ⚠️ If you are using the brick in a Trigger, set the Root Mode of the brick to
Document
. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event
Highlighting Cells
- Add the “Highlight AARI Table Cells” brick
- ⚠️ If you are using the brick in a Trigger, set the Root Mode of the brick to
Document
. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event
Appending a Row to a Table
- Add the “Append AARI table row” brick
- Provide the table selector based on the field name of the table, e.g.,
#Table1
- Provide an array of values to write in the new row. You can also pass an array of values
- ⚠️ If you are using the brick in a Trigger, set the Root Mode of the brick to
Document
. If set to Inherit, PixieBrix will not find the table because it will search within the element that triggered the event
Table Validation and Calculations
Example: Checking Aggregate Values
- Add the
@pixiebrix/jq
brick - Pass the output key of the “Read AARI Table Field” brick for the data property
- The check if the value in the last row is equal to the sum of the proceeding columns, use the following jq filter:
Property | Value |
filter | (.rows[-1]["Column 1"] | tonumber) == (.rows[0:-1] | map(.["Column 1"] | tonumber) | add) |
data | @table |
The (.rows[-1]["Column 1"] | tonumber)
expression gets the value in the last row and converts it to a number
The (.rows[0:-1] | map(.["Column 1"] | tonumber) | add)
expression gets the proceeding rows, converts the value in Column 1 to a number, and sums the values
Example: Multi-Column Validation
- Add the
@pixiebrix/jq
brick - Pass the output key of the “Read AARI Table Field” brick for the data property
- To report rows where the value in “Column 1” is greater than the value in “Column 2”, use the following jq filter:
Property | Value |
filter | .rows | map((.["Column 1"] | tonumber) > (.["Column 2"] | tonumber)) | to_entries | map(select(.value)) | map({row: .key, column: 1}) |
data | @table |
.row |
# Map to an array of true/false with the condition
map((.["Column 1"] | tonumber) > (.["Column 2"] | tonumber)) |
# Map to an array of records with {key: <row index>, value: <condition>}
to_entries |
# Exclude entries where the condition is false
map(select(.value)) |
# Map to an array of rows/columns indexes (e.g., to pass to the Highlight AARI Table Cells brick)
map({row: .key, column: 1})
- Pass the output of the jq brick to the Highlight AARI Table Cells brick
Writing Table Selectors
Table Selectors
The AARI Table Fields can each be targeted with a selector corresponding to the field in the form #Table0
, #Table1
Column Selectors
To target a particular column in the table, you can:
- Target the column id:
#Table1 td:has(#Table1_col0-defaultValue)
. NOTE: the column id is not necessarily the column index. The column id is dependent on which order the the columns were added during AARI form creation - Target the column by index (1-indexed):
#Table1 td.preview-table__body-column:nth-child(1)
Known Limitations
“Attach Autocomplete” brick fills multiple cells when a value is selected
There is a known issue when selecting a value from Attach Autocomplete brick that it fills all the inputs matching the selector. (I.e., as opposed to only filling the input for which the autocomplete was shown)