Question type

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).

Mockup preview
QBudget gridnumber
Allocate spend across category × month.
- 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

PropertyValuesNotes
qidstringRequired. Unique within the survey.
typegridNumberRequired.
title, text, instructionrenderableVisible content. Use {{ }} to pipe runtime values. HTML allowed.
requiredTrue | FalseDefault True.
default.errorsTrue | False | custom stringDefault True.
validationcode blockPython; call fail() to reject. No default.
readonlyTrue | FalseDefault 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.
visibilityshow | hideDefault show.
stylegrid | dropdownDefault grid. See Styles below.
rowslist name or inline domainRequired. The rows of the grid. Note: rows: not options:.
colslist name or inline domainRequired. The columns of the grid. Note: cols: not scale:.
orderkeyword or expressionRow 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.ordersame as orderDefault fixed. Column order.
directionrows | colsDefault rows. Where running totals are placed and how export columns are named. See The direction rule.
totalTrue | FalseDefault False. Set True to show the running total per row (or per column, depending on direction).
total.labelstringOptional label for the totals row/column header.
total.maxnumberCap on row / column totals. The runtime rejects answers when any total exceeds this.
minnumberNumeric lower bound for every cell. No default.
maxnumberNumeric upper bound for every cell. No default.
decimalTrue | FalseDefault False. Allow fractional values.
decimal.placesintegerCap precision when decimal: True. No default.
label.prefixstringDecoration on the left of each cell input (e.g. $).
label.suffixstringDecoration on the right (e.g. %, kg).
input.sizeintegerWidth of each cell input in characters. No default.
layout.widthstringCustom width override.
customcode blockCustom runtime block. No default.
dataobjectMetadata 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.

PropertyValuesNotes
labelrenderableRequired when expanding the entry.
anchorTrue | FalseDefault False. Pin in place under order: random or col.order: random.
isolateTrue | FalseDefault 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.
dataobjectMetadata. No default.

The direction rule

direction controls two things at once:

  1. Where running totals render in the UI (when total: True).
  2. How export columns are named (the column-naming convention inverts based on direction — see Column naming).
directionTotals placementExport column pattern
rows (default)One total per row, on the rightqidrNcM
colsOne total per column, at the bottomqidcNrM

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

ExpressionReturnsMeaning
Q.answeredboolTrue if any cell has a value.
Q.notAnsweredboolInverse.
No question-level 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.

ExpressionReturnsMeaning
Q.row(N).valuesNumberListCell values across the row, in column order. null for empty cells.
Q.row(N).labelLabelThe row’s label.
Q.row(N).answeredboolTrue if any cell in the row has a value.
Q.row(N).notAnsweredboolInverse.

Column accessors

Q.col(M) returns a column proxy. Same shape as a row proxy, just on the column dimension.

ExpressionReturnsMeaning
Q.col(M).valuesNumberListCell values down the column, in row order. null for empty cells.
Q.col(M).labelLabelThe column’s label.
Q.col(M).answeredboolTrue if any cell in the column has a value.
Need a row or column total? Use 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).

ExpressionReturnsMeaning
Q.row(N).col(M).valuenumberThe number in row N, column M. None if unanswered.
Q.row(N).col(M).answeredboolTrue once the cell has a value.
Q.row(N).col(M).inactiveboolTrue if the cell is hidden (e.g. by isolate or other masks).

Methods

Question methods

ExpressionReturnsMeaning
Q.reset()NoneClear every cell.
Q.row(N)RowObjectReturns a row proxy.
Q.col(M)ColObjectReturns a column proxy.
Q.at(N)RowObjectSame as Q.row(N).

Cell methods

ExpressionReturnsMeaning
Q.row(N).col(M).set(N)NoneSet a single cell to a number.
Q.row(N).col(M).reset()NoneClear a single cell.
Writes are per-cell. Set values one cell at a time with 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)
Q1Q2Q3
Apple 100 120 95
Sony 80 75 90
Numeric input matrix — one open input per cell. Default. Best for any value where the respondent should type.
dropdown Dropdown
Q1Q2Q3
Apple 8 ▾ 7 ▾ 9 ▾
Sony 6 ▾ 5 ▾ 8 ▾
Dropdown select in each cell. Best for short bounded ranges (e.g. 1–10) where you want to constrain the input shape.

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.

Mockup preview
QHours gridnumber
Hours per day on each activity, by day of the week.
Live state
QHours.answeredFalse
QHours.valueNone
QHours.selected{}
QHours.selectedLabelNone
QHours.selected.size0
Live state
QHours.answeredFalse
QHours.row(1).total0
QHours.col(1).total0
QHours.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.

Mockup preview
QSpend gridnumber
Spend per category, by quarter.
Methods & accessors — live
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() — write sum(Q.row(N).values) or sum(Q.col(M).values) rather than reaching for a dedicated accessor. sum() treats null cells as zero.
  • Q.row(N).col(M) and Q.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).value is None for unanswered cells, not 0. sum() treats None as zero, but a direct .value read returns None. Use or 0 when 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 required gate + 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 — reading 1 when 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:

directionColumn patternExample
rowsqidrNcMQBudgetr1c1, QBudgetr1c2, QBudgetr2c1, …
colsqidcNrMQBudgetc1r1, 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