gridNumber
A 2D numeric grid — rows × columns of number inputs, one number per cell. Spending matrices, time-allocation tables, multi-dimensional ratings.
What gridNumber is
gridNumber is a true 2D numeric grid: rows and columns are both
authored, and each cell stores one number. Unlike gridSingle /
gridMulti, the column dimension is cols: not scale:, and
the row dimension is rows: not options: — the names reflect
the symmetric 2D nature of the data. Direction-aware running totals
sit on the right (direction: rows) or under each column
(direction: cols).
- qid: QBudget
type: gridNumber
text: Allocate spend across category × month.
direction: rows
total: True
label.prefix: $
min: 0
rows:
1: Groceries
2: Transport
3: Entertainment
cols:
1: Jan
2: Feb
3: Mar
Properties
| Property | Values | Notes |
|---|---|---|
qid | string | Required. Unique within the survey. |
type | gridNumber | Required. |
title, text, instruction | renderable | Visible content. Use {{ }} to pipe runtime values. HTML allowed. |
required | True | False | Default True. |
default.errors | True | False | custom string | Default True. |
validation | code block | Python; call fail() to reject. No default. |
readonly | True | False | Default False. Set True to render the question but disable input — the respondent sees the cells but can’t change the values. Pair with visibility: hide to fully hide a helper question. |
visibility | show | hide | Default show. |
style | grid | dropdown | Default grid. See Styles below. |
rows | list name or inline domain | Required. The rows of the grid. Note: rows: not options:. |
cols | list name or inline domain | Required. The columns of the grid. Note: cols: not scale:. |
order | keyword or expression | Row order. Keywords: fixed (default), random, randomEach, alphabetical, reverse, flip. Also accepts an expression (e.g. Q1.all). col.order (alias of scale.order) takes the same forms for columns. See Order. |
col.order | same as order | Default fixed. Column order. |
direction | rows | cols | Default rows. Where running totals are placed and how export columns are named. See The direction rule. |
total | True | False | Default False. Set True to show the running total per row (or per column, depending on direction). |
total.label | string | Optional label for the totals row/column header. |
total.max | number | Cap on row / column totals. The runtime rejects answers when any total exceeds this. |
min | number | Numeric lower bound for every cell. No default. |
max | number | Numeric upper bound for every cell. No default. |
decimal | True | False | Default False. Allow fractional values. |
decimal.places | integer | Cap precision when decimal: True. No default. |
label.prefix | string | Decoration on the left of each cell input (e.g. $). |
label.suffix | string | Decoration on the right (e.g. %, kg). |
input.size | integer | Width of each cell input in characters. No default. |
layout.width | string | Custom width override. |
custom | code block | Custom runtime block. No default. |
data | object | Metadata object for advanced authoring. No default. |
rows: and cols:, not options: and scale:. The other grid types use options: for rows and scale: for columns. gridNumber uses rows: / cols: because both axes carry the same kind of authored data — they’re peers. Using the wrong property name fails validation.Per-axis properties
rows: entries and cols: entries share the same per-axis property
set. Expand an entry to a map to attach behaviour.
| Property | Values | Notes |
|---|---|---|
label | renderable | Required when expanding the entry. |
anchor | True | False | Default False. Pin in place under order: random or col.order: random. |
isolate | True | False | Default False. Set True to render this row or column as a separate toggle outside the matrix — a “this dimension does not apply” opt-out. When the respondent activates the toggle, the cells along that axis are cleared and disabled. Use sparingly. |
data | object | Metadata. No default. |
The direction rule
direction controls two things at once:
- Where running totals render in the UI (when
total: True). - How export columns are named (the column-naming convention inverts based on direction — see Column naming).
direction | Totals placement | Export column pattern |
|---|---|---|
rows (default) | One total per row, on the right | qidrNcM |
cols | One total per column, at the bottom | qidcNrM |
Switching direction after fielding renames every export column for
the question. Pick the direction that matches how the analyst wants
to sum.
Methods & accessors
Accessors
Question accessors
| Expression | Returns | Meaning |
|---|---|---|
Q.answered | bool | True if any cell has a value. |
Q.notAnswered | bool | Inverse. |
selected or values. The data is two-dimensional; reads happen per row or per column. Use Q.row(N) or Q.col(M) to descend, then .values for that slice and sum(…) if you need a running total.Row accessors
Q.row(N) returns a row proxy.
| Expression | Returns | Meaning |
|---|---|---|
Q.row(N).values | NumberList | Cell values across the row, in column order. null for empty cells. |
Q.row(N).label | Label | The row’s label. |
Q.row(N).answered | bool | True if any cell in the row has a value. |
Q.row(N).notAnswered | bool | Inverse. |
Column accessors
Q.col(M) returns a column proxy. Same shape as a row proxy, just
on the column dimension.
| Expression | Returns | Meaning |
|---|---|---|
Q.col(M).values | NumberList | Cell values down the column, in row order. null for empty cells. |
Q.col(M).label | Label | The column’s label. |
Q.col(M).answered | bool | True if any cell in the column has a value. |
sum(Q.row(N).values) or sum(Q.col(M).values) — sum() treats null cells as zero. Keeps the accessor surface small and the formula explicit at the call site.Cell accessors
Drill down to a specific cell with Q.row(N).col(M) (or
Q.col(M).row(N) — same target, just a different traversal path).
| Expression | Returns | Meaning |
|---|---|---|
Q.row(N).col(M).value | number | The number in row N, column M. None if unanswered. |
Q.row(N).col(M).answered | bool | True once the cell has a value. |
Q.row(N).col(M).inactive | bool | True if the cell is hidden (e.g. by isolate or other masks). |
Methods
Question methods
| Expression | Returns | Meaning |
|---|---|---|
Q.reset() | None | Clear every cell. |
Q.row(N) | RowObject | Returns a row proxy. |
Q.col(M) | ColObject | Returns a column proxy. |
Q.at(N) | RowObject | Same as Q.row(N). |
Cell methods
| Expression | Returns | Meaning |
|---|---|---|
Q.row(N).col(M).set(N) | None | Set a single cell to a number. |
Q.row(N).col(M).reset() | None | Clear a single cell. |
Q.row(N).col(M).set(value). To clear, use Q.row(N).col(M).reset() for a single cell or Q.reset() for the whole grid. There are no bulk row/column setters or row/column-scope .reset() on gridNumber — write or clear each cell explicitly when you need to touch multiple values.Skins
Two visual styles. Pick by whether the value is open-ended or drawn from a short bounded set.
grid Grid (default) dropdown Dropdown The exact appearance is driven by theme tokens — colours, radii, fonts. See Customisation.
See it work
A working preview. Type values into the cells and watch the Live state panel.
QHours.answeredFalseQHours.valueNoneQHours.selected{}QHours.selectedLabelNoneQHours.selected.size0QHours.answeredFalseQHours.row(1).total0QHours.col(1).total0QHours.row(1).col(1).valueNone- qid: QHours
type: gridNumber
text: Hours per day on each activity, by day of the week.
direction: cols
total: True
total.max: 24
min: 0
max: 24
rows:
1: Sleep
2: Work
3: Other
cols:
1: Mon
2: Tue
3: Wed
direction: cols means each column (day) sums to total.max: 24 — 24 hours in a day. The totals row appears under the cells
because of the direction.
Methods & accessors — live
Type values into the cells and watch each expression evaluate.
QSpend.answered → — QSpend.row(1).answered → — QSpend.row(1).label → — QSpend.col(1).label → — QSpend.row(1).col(1).value → — QSpend.row(1).col(1).answered → — QSpend.row(2).col(3).value → — A few things to notice:
- Row / column totals come from
sum()— writesum(Q.row(N).values)orsum(Q.col(M).values)rather than reaching for a dedicated accessor.sum()treatsnullcells as zero. Q.row(N).col(M)andQ.col(M).row(N)are equivalent paths to the same cell. Use whichever reads more naturally at the call site.Q.row(N).col(M).valueisNonefor unanswered cells, not0.sum()treatsNoneas zero, but a direct.valueread returnsNone. Useor 0when arithmetic needs a safe default.
Examples
Allocate hours across a week
- qid: QHours
type: gridNumber
text: Hours per day on each activity.
direction: cols
total: True
total.max: 24
min: 0
max: 24
rows:
1: Sleep
2: Work
3: Eat
4: Other
cols:
1: Mon
2: Tue
3: Wed
4: Thu
5: Fri
6: Sat
7: Sun
direction: cols puts the total under each day (column). total.max: 24 enforces 24 hours per day; the runtime rejects submissions where
any column total exceeds 24.
Spend matrix with row totals
- qid: QSpend
type: gridNumber
text: Spend per category × month.
direction: rows
total: True
label.prefix: $
min: 0
decimal: True
decimal.places: 2
rows: spendCategories
cols: monthList
direction: rows shows a category total on the right of each row.
Per-cell currency formatting via label.prefix: $.
Cap on a single cell with validation
- qid: QSpend
type: gridNumber
text: Spend per category × month.
rows: spendCategories
cols: monthList
min: 0
max: 5000
validation: |
# Reinforce the per-cell cap with a friendlier message.
for r in [1, 2, 3]:
for c in [1, 2, 3]:
if (QSpend.row(r).col(c).value or 0) > 5000:
fail("No single cell can exceed $5,000.")
max: 5000 is the everyday cap — the input rejects out-of-range
values up front. The validation block adds a custom message for
any cell that slips through (e.g. via paste). Iterate over the row
and column codes you authored; the or 0 guards against None from
unanswered cells.
Pipe a row total into a follow-up
- qid: QSpend
type: gridNumber
rows: spendCategories
cols: monthList
- qid: QGroceries
type: open
text: You spent ${{ sum(QSpend.row(1).values) }} on groceries this period — what changed?
if: QSpend.row(1).answered
style: textarea
sum(Q.row(1).values) adds the row’s cells (treating empty cells
as zero) and the result pipes straight into the follow-up question’s
text.
Advanced
Seeding cells programmatically
There is no bulk Q.set({...}) form on gridNumber — every write
goes through Q.row(N).col(M).set(value). To pre-populate a grid
from another question or from carried-forward data, loop the codes
you authored:
- qid: QSpendPrev
type: gridNumber
rows: spendCategories
cols: monthList
- qid: QSpendCurr
type: gridNumber
rows: spendCategories
cols: monthList
- script: |
# Carry last period's values into the current grid.
for r in [1, 2, 3]:
for c in [1, 2, 3]:
v = QSpendPrev.row(r).col(c).value
if v is not None:
QSpendCurr.row(r).col(c).set(v)
The respondent sees their previous-period spend pre-filled, ready to confirm or adjust. Per-cell writes are how the runtime keeps validation, totals, and the export schema in sync — there is no shortcut.
isolate — opt-out toggle
isolate: True renders the row or column as a toggle
outside the matrix — a “this dimension does not apply” opt-out.
When the respondent activates it:
- Every cell along that axis is cleared and disabled
- The whole-question
requiredgate + the “fill all cells” constraint are waived for that axis - The export gets a single flag column naming the isolated axis —
<qid>r<code>for a row-axis opt-out or<qid>c<code>for a column-axis opt-out — reading1when the toggle is active. No per-cell null cross product is emitted for the isolated axis.
- qid: QBudget
type: gridNumber
text: How much did you spend on each category, per month?
total.max: 5000
rows:
1: Groceries
2: Utilities
3: Transportation
98:
label: I don't track this
isolate: True
exclusive: True
cols:
1: Jan
2: Feb
3: Mar
When the respondent ticks “I don’t track this”, every row (1, 2, 3) is cleared and disabled, total.max is waived, and the export gets QBudgetr98 = 1 with every QBudgetr{1,2,3}c* cell reading null.
isolate does not create a “header band” or “subtotal row”;
those patterns aren’t supported on gridNumber. If you need a
contextual annotation, attach it to instruction or use a separate
info question above the grid.
Export
gridNumber exports one column per cell, with the column-naming
pattern depending on direction:
direction | Column pattern | Example |
|---|---|---|
rows | qidrNcM | QBudgetr1c1, QBudgetr1c2, QBudgetr2c1, … |
cols | qidcNrM | QBudgetc1r1, QBudgetc2r1, QBudgetc1r2, … |
Empty cells export as null. Inside a loop the suffix appends:
QBudgetr1c1_3 (row 1, col 1, loop iteration 3). See
Column naming and
Loop suffixes.
An isolate axis opt-out contributes one additional flag column instead of the per-cell cross product: <qid>r<code> (row-axis opt-out) or <qid>c<code> (column-axis opt-out), reading 1 when the toggle is active.
See also
- number — single numeric input.
- numberList — list of numeric inputs (rows only, no columns).
- gridSingle — radio scale per row.
- gridMulti — checkbox scale per row.
- Column naming —
directionrule and column patterns. - Constraints —
total.max,min/maxper cell. - Row & cell access —
.row(N).col(M)semantics.