Skip to content

Matrix Grid

A grid of row labels, each with a hint, by column headers, with a control in each cell: a toggle, a select, a number box, a text box, or a time box, or a read only badge or text. It is a Data Table whose cells hold controls, so it shares its column tracks, its compact layout with icon headings, its hidden columns, and its sideways scroll inside its frame.

Decision

When Use
Setting the same few things for many rows, such as what each library syncs Matrix Grid
A read only table of what each role can do Matrix Grid with badge columns
Pairing each row with one target Mapping Table
A flat set of boxes Check Grid

Usage

import { createMatrixGrid } from './configurationpage?name=myplugin_stolon.js';

var grid = createMatrixGrid({
    rows: libraries.map(function (l) { return { key: l.Id, label: l.Name, hint: l.Count + ' items' }; }),
    columns: [
        { key: 'watched', label: 'Watched', icon: 'visibility' },
        { key: 'ratings', label: 'Ratings', icon: 'star' },
        { key: 'mode', label: 'Mode', type: 'select', options: ['Copy', 'Link'] }
    ],
    value: config.LibrarySync,
    onChange: function (value) { config.LibrarySync = value; }
});
view.querySelector('#gridHost').appendChild(grid.element);

A bandwidth table, whose Hours row holds time boxes under the speed columns, with the Scheduled column hidden while scheduling is off:

var speeds = createMatrixGrid({
    rows: [
        { key: 'downloads', label: 'Downloads', hint: 'Shared by every download to here' },
        { key: 'hours', label: 'Hours', hint: 'Uses the server clock', cells: { normal: { type: 'time', unit: '' }, scheduled: { type: 'time', unit: '' } } }
    ],
    columns: [
        { key: 'normal', label: 'Normal', type: 'number', min: 0, unit: 'Mbps' },
        { key: 'scheduled', label: 'Scheduled', type: 'number', min: 0, unit: 'Mbps', hidden: !config.EnableBandwidthScheduling }
    ],
    note: '0 is no limit.'
});
scheduleToggle.addEventListener('change', function () { speeds.setColumnHidden('scheduled', !scheduleToggle.checked); });

Classes: stolon-matrix-grid, stolon-matrix-cell, stolon-matrix-label, stolon-matrix-name, stolon-matrix-hint, stolon-matrix-badge, stolon-matrix-static, stolon-matrix-text, stolon-matrix-empty, stolon-matrix-note. The handle is { element, getValue, setValue, setRows, isValid, setColumnHidden, destroy }. setRows draws other rows and keeps every value.

States and Modifiers

  • The value is { rowKey: { columnKey: value } }. A cell with no value starts from its control, off for a toggle and the first choice for a select.
  • A row is { key, label, hint, cells }, and the hint shows dimmed under the label.
  • A column is { key, label, icon, type, options, min, max, step, placeholder, unit, hidden }. type is toggle (default), select, number, text, time, or the read only badge and static. A select's options are values or { value, label }. A toggle column takes the narrow number track.
  • unit on a number column, such as Mbps, is drawn dimmed inside each box before its arrows, through the Field Adornments unit, and is never typed.
  • A row's cells changes its own cell in a column by the column's key. A part of a column, such as { type: 'time' } or { unit: 'to', max: 23 }, replaces those settings for that one cell, and null leaves the cell empty, with no control and no value.
  • A badge cell shows its value as a Badge. The value is the label, or { label, color } where color is a status color name, a hex code, or a badge state name, gray by default. A static cell shows its value as text. Neither takes input, their values pass through getValue as given, and isValid skips them. A cell with no value is blank.
  • hidden: true starts a column hidden, and setColumnHidden(key, hidden) hides or shows its heading and its cells. The other columns share the width, and isValid skips a hidden column, while its values stay in getValue.
  • disabled: true on a column, or on a row's part of one, greys out the cell's control. It shows its value, takes no input, and isValid skips it.
  • note is a dimmed line under the grid, for a rule that applies to every row.
  • Each control is named "{column} for {row}" by cellLabel, and checks through the validation core, so a number out of range shows its message in the cell. isValid() checks every shown cell that takes input.
  • rowHeader heads the label column, empty by default. label names the grid, "Grid" by default, and emptyText shows while there is no row, "Nothing to show." by default.
  • onChange(value, rowKey, columnKey) runs after a cell changes.
  • A grid too narrow for its columns turns compact as the Data Table does, and a column with icon shows the icon in its heading.

Reference

Generated from the code by scripts/build-docs.mjs. Edit the code, not this section.

createMatrixGrid

function createMatrixGrid(options: MatrixGridOptions): MatrixGridHandle

A grid of row labels, each with a hint, by column headers, with a control in each cell: a toggle, a select, a number box, a text box, or a time box, or a read only badge or text. It is a Data Table whose cells hold controls, so it shares its column tracks, its compact layout with icon headings, its hidden columns, and its sideways scroll inside its frame.

Option Type What it does
rows (required) MatrixGridRow[] array of { key, label, hint, cells (by column key, part of a column that changes this row's cell, or null for an empty cell) } [required]
columns (required) MatrixGridColumn[] array of { key, label, icon, type ('toggle', 'select', 'number', 'text', 'time', or the read only 'badge' and 'static'; default 'toggle'), options, min, max, step, placeholder, unit (a number's suffix inside its box), hidden (default false), disabled (greys out the cells, which keep their value; default false) } [required]
value MatrixGridValue | null object of row key to an object of column key to value [optional]
rowHeader string header of the label column (default '')
cellLabel string aria-label of a cell's control, where {column} and {row} are the labels (default '{column} for {row}')
label string aria-label of the grid (default 'Grid')
emptyText string shown while there is no row (default 'Nothing to show.')
size 'small' | 'medium' | 'large' 'small', 'medium', or 'large' for its fields (default 'medium')
note string a dimmed line under the grid [optional]
onChange (value: MatrixGridValue, rowKey: string, columnKey: string): void function(value, rowKey, columnKey) after a cell changes [optional]
Handle member Type
getValue (): MatrixGridValue
setValue (next: MatrixGridValue | null): void
setRows (rows: MatrixGridRow[] | null): void
isValid (): boolean
setColumnHidden (key: string, hidden: boolean): void
destroy (): void
Type What it is
MatrixGridRow One row of the grid: its key, its label, and a dimmed hint under the label. cells changes a cell of this row by column key, such as its type, options, or unit, or null leaves that cell empty.
MatrixGridColumn One column: its key, its header, an icon the header shows when the grid is narrow, and the control in each of its cells. badge and static cells show their value and take no input. unit is a number's fixed suffix inside its box, and disabled greys out the control so it shows its value and takes no input, as a row's cells can do for one cell.
MatrixGridBadge A badge cell's value: its label, or { label, color } where color is a status color name, a hex code, or a badge state name.
MatrixGridValue Every cell's value, by row key and then column key.
Class What it looks like
stolon-matrix-grid A Data Table of row labels by column headers with a control in each cell, on the table's own column tracks, compact layout, and sideways scroll
stolon-matrix-label A row's label over its dimmed hint, each ending in an ellipsis with the full text in its tooltip
stolon-matrix-cell One cell's control with its message under it. A toggle column takes the narrow number track with its box centered under its heading
stolon-matrix-badge A read only cell that shows its value as a badge or as text, centered on the row's line, with no control
stolon-matrix-note A dimmed line under the grid, inset to its rows
stolon-matrix-grid.stolon-has-units A grid with a unit in its number boxes, whose columns keep room for the digits, the unit, and the arrows, and scroll sideways before they would hide digits
stolon-matrix-cell.stolon-disabled A disabled cell, its control greyed out with its value still shown

Example

Example Code

<!-- title: Matrix Grid -->
<div id="grid"></div>
<p class="fieldDescription">Units inside the number boxes, an Hours row of time boxes, a hidden column, and a note.</p>
<div id="scheduleOn"></div>
<div id="speeds"></div>
<p class="fieldDescription">Read only badge columns.</p>
<div id="roles"></div>
<script type="module">
const base = await window.__baseReady;
const grid = base.createMatrixGrid({
    rows: [
        { key: 'movies', label: 'Movies', hint: '1,204 items' },
        { key: 'shows', label: 'Shows', hint: '86 series' },
        { key: 'music', label: 'Music', hint: '12,480 tracks' }
    ],
    columns: [
        { key: 'watched', label: 'Watched', icon: 'visibility' },
        { key: 'ratings', label: 'Ratings', icon: 'star' },
        { key: 'mode', label: 'Mode', type: 'select', options: ['Copy', 'Link'] },
        { key: 'limit', label: 'Limit', type: 'number', min: 0, max: 500 }
    ],
    rowHeader: 'Library',
    value: { movies: { watched: true, ratings: true, mode: 'Link', limit: 100 }, shows: { watched: true } }
});
document.getElementById('grid').appendChild(grid.element);

const speeds = base.createMatrixGrid({
    rows: [
        { key: 'downloads', label: 'Downloads', hint: 'Shared by every download to here' },
        { key: 'main', label: 'Main Server', hint: 'Streams from this server' },
        { key: 'hours', label: 'Hours', hint: 'Uses the server clock', cells: { normal: { type: 'time', unit: '' }, scheduled: { type: 'time', unit: '' } } }
    ],
    columns: [
        { key: 'normal', label: 'Normal', type: 'number', min: 0, unit: 'Mbps' },
        { key: 'scheduled', label: 'Scheduled', type: 'number', min: 0, unit: 'Mbps' }
    ],
    rowHeader: 'Limit',
    label: 'Bandwidth',
    note: 'Set stream speeds above the bitrate of your files, or playback buffers. 0 is no limit.',
    value: { downloads: { normal: 100, scheduled: 20 }, main: { normal: 40, scheduled: 10 }, hours: { normal: '22:00', scheduled: '06:00' } }
});
document.getElementById('speeds').appendChild(speeds.element);
document.getElementById('scheduleOn').appendChild(base.createCheckbox({ label: 'Scheduled Speeds', checked: true, onChange: function (on) { speeds.setColumnHidden('scheduled', !on); } }).element);

const yes = { label: 'Yes', color: 'green' };
const no = { label: 'No', color: 'red' };
const limited = { label: 'Limited', color: 'orange' };
const roles = base.createMatrixGrid({
    rows: [
        { key: 'visible', label: 'Libraries the user can see' },
        { key: 'every', label: 'Every library' },
        { key: 'downloads', label: 'File downloads' },
        { key: 'live', label: 'New files as they happen', hint: 'Needs the user on the whitelist' }
    ],
    columns: [
        { key: 'user', label: 'User', type: 'badge' },
        { key: 'admin', label: 'Admin', type: 'badge' }
    ],
    rowHeader: 'Permission',
    label: 'Permissions',
    note: 'Signed in users need Allow Media Downloading.',
    value: { visible: { user: yes, admin: yes }, every: { user: no, admin: yes }, downloads: { user: limited, admin: yes }, live: { user: limited, admin: yes } }
});
document.getElementById('roles').appendChild(roles.element);
</script>