SpreadsheetGrid
Guides

Values and labels

In columns whose values are codes and whose screen shows display names, align group headings, the global filter, and copy and paste with the display names (groupLabel / globalFilterMatch / clipboard)

Columns whose values are codes ('kanto' / 'transport') and whose screen shows display names ("East", "Travel") show the display name with valueFormatter. On top of that, the following three align the remaining places with the display names (since 1.1.0). All of them default to the same as 1.0 (the value text).

PlaceDefaultTo use display names
Group row headingsThe value text (kanto (8 rows))The column's groupLabel: 'formatted'
The global filter (the top bar's search box, globalText of applyState, /ai search)Searches the value textglobalFilterMatch="both" (values or display names) / "display" (display names only)
Copy, CSV and paste (select columns)The value text. Pasted display names go in as they areThe select editor's clipboard: 'label'

Demo (expenses)

Rows 24 of 24Columns 2 of 3Sort: —
#
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
Rows 24 of 24Columns 2 of 3
Cell —Range —0 cells / 0 rows0 columns

Type "Central" or "chubu" in the search box of the top bar to see the difference / copy a Type cell with Ctrl (⌘)+C and paste it into another cell (with label it comes out as the display name and goes back to the value when pasted) / select and copy this text, then paste it into a Type cell: Supplies

  • Region and Type have codes as values. Setting groupLabel to value turns the group row headings back into codes.
  • Type "Central" in the top bar's search box: with globalFilterMatch at value there are 0 results; with both / display the Central rows remain. "chubu" matches with both / value. Thousands separators such as "1,200" in Amount are screen text, so they match with both / display.
  • Copy a Type cell, and with clipboard at label you get the display name ("Travel"). Pasting a display name puts the value ('transport') in (with value, the text goes in as is, and the cell shows that text too).

Column definitions

import { SpreadsheetGrid, type GridColumn, type GridSelectEditorOption } from '@ishibashi0112/spreadsheet-grid';

const REGIONS: GridSelectEditorOption[] = [
  { value: 'kanto', label: 'East' },
  { value: 'chubu', label: 'Central' },
];
const regionLabel = new Map(REGIONS.map((o) => [o.value, o.label]));

const columns: GridColumn<Expense>[] = [
  {
    key: 'region',
    title: 'Region',
    width: 110,
    editable: true,
    editor: { type: 'select', options: REGIONS, clipboard: 'label' },
    valueFormatter: ({ value }) => regionLabel.get(String(value)) ?? String(value ?? ''),
    rowGroup: true,
    groupLabel: 'formatted',
  },
  // ...
];

<SpreadsheetGrid rows={rows} columns={columns} globalFilterMatch="both" />;

Fine print

  • groupLabel — 'formatted' uses the column's valueFormatter (or the value text if none); a function uses its return value (({ value, row, column }) => string, where row is the group's first row). Blank groups stay "(Blank)". The label of getGroupRows() is the same text. Headings of subtotal rows in exports (includeGroupRows) follow the same rules as copy (formatClipboardValue / clipboard: 'label').
  • globalFilterMatch — the screen text is the result of valueFormatter. The label of status chips (conditionalFormat.chips) and the contents of renderCell aren't looked at. It's a clientSide-only setting; with serverSide (dataSource), the global filter text is just passed to the server (the server decides whether to search display names too). It doesn't filter with manualFiltering either. Find in cells (find) always searches the screen text.
  • Column filter options — options of set / select column filters (the checkbox list) gathered from rows are listed as values (codes) (not passed through valueFormatter). To show display names, pass the same options ({ value, label }) to the column's filterOptions (filterOptions: REGIONS). Filter chips in the top bar and condition summaries in the tool panel already show the label from filterOptions or the select editor's options. Columns given filterOptions don't use the "all minus the unchosen values" form; the condition is only the chosen values (the options don't necessarily cover all values).
  • clipboard: 'label' — copy (Ctrl / ⌘+C), CSV / TSV and the text of getExportData use the option's label (value stays the value; options with an empty label use the value text). Pasted text becomes the option's value if it's an option's label (compared after trimming), stays as is if it's a value, and otherwise goes in as raw text (labels are checked first, so even if one option's label is the same text as another option's value, values copied and pasted within the table don't change. If the pasted text equals the label of the current value, the current value stays, so re-pasting doesn't change the value even for options with overlapping labels (options differing only in description) (since 1.7.0). Pasting into other cells gives the first option with that label, so keeping labels unique is the safe way. Options chosen in the editor write their value without this mapping) (to refuse it, use 'reject' with the column's validate). The column's formatClipboardValue / parseClipboardValue win if present. For columns other than select (columns that only show codes with valueFormatter), write formatClipboardValue / parseClipboardValue to do the same.

On this page