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).
| Place | Default | To use display names |
|---|---|---|
| Group row headings | The 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 text | globalFilterMatch="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 are | The select editor's clipboard: 'label' |
Demo (expenses)
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
groupLabeltovalueturns the group row headings back into codes. - Type "Central" in the top bar's search box: with
globalFilterMatchatvaluethere are 0 results; withboth/displaythe Central rows remain. "chubu" matches withboth/value. Thousands separators such as "1,200" in Amount are screen text, so they match withboth/display. - Copy a Type cell, and with
clipboardatlabelyou get the display name ("Travel"). Pasting a display name puts the value ('transport') in (withvalue, 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'svalueFormatter(or the value text if none); a function uses its return value (({ value, row, column }) => string, whererowis the group's first row). Blank groups stay "(Blank)". ThelabelofgetGroupRows()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 ofvalueFormatter. Thelabelof status chips (conditionalFormat.chips) and the contents ofrenderCellaren'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 withmanualFilteringeither. 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'sfilterOptions(filterOptions: REGIONS). Filter chips in the top bar and condition summaries in the tool panel already show the label fromfilterOptionsor the select editor'soptions. Columns givenfilterOptionsdon'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 thetextofgetExportDatause the option's label (valuestays 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 indescription) (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'svalidate). The column'sformatClipboardValue/parseClipboardValuewin if present. For columns other than select (columns that only show codes withvalueFormatter), writeformatClipboardValue/parseClipboardValueto do the same.