Multi-select
Choose any number of options in one cell with the select editor's multiple (chips, a checked list, copy and paste, column filters)
Write multiple: true on a select editor, and any number of options can be chosen in one cell (since 1.11.0). It's for columns where one row has several values, such as owners, tags or skills. Cells show chips with the chosen option names, and the editor shows a list of options (with checks) below. Select columns without multiple work as before.
Demo (team members)
- Skills — select a cell and open with
Enter(orF2/ double-click). Move the highlight with↑/↓, toggle the check withSpace, and commit withEnter. Pressing an option only toggles its check; it doesn't commit.Escapecancels, and when focus leaves by pressing somewhere else, it commits. - Choose "React" in the filter of the Skills header, and rows that contain React remain.
- Projects — a column you can narrow by typing (
search: true). Type and pressEnterto add the highlighted option.Spaceright after typing is a space character;Spaceafter moving the highlight with↑/↓toggles the check.Backspacewith nothing typed removes the last value. The chip's×removes it too. - Mentors — a column that fetches options from a server (
loadOptions; it waits 300ms). - Select a cell and press
Ctrl+Cto get the values joined with ", " (react, designand so on). Pasting text such asTypeScript, Gofrom a spreadsheet splits it at the separators and matches the options.
Usage
import { SpreadsheetGrid, type GridColumn, type GridSelectEditorOption } from '@ishibashi0112/spreadsheet-grid';
type Member = { id: number; name: string; skills: string[] };
const SKILLS: GridSelectEditorOption[] = [
{ value: 'ts', label: 'TypeScript' },
{ value: 'react', label: 'React' },
{ value: 'go', label: 'Go' },
];
const columns: GridColumn<Member>[] = [
{ key: 'name', title: 'Name', width: 110 },
{
key: 'skills',
title: 'Skills',
width: 230,
editable: true,
filterType: 'set',
editor: { type: 'select', multiple: true, options: SKILLS },
},
];
<SpreadsheetGrid rows={rows} onRowsChange={setRows} columns={columns} />;Values
- The value is an array of the options'
value(string[]). When nothing is chosen, write[](null/undefinedare treated the same as[]). - The order follows the order of the options (not the order of choosing). Values not in the options stay at the end in their original order, and duplicates become one.
- Comparison is by contents. Opening and committing without changes writes nothing, and change tracking and change highlights treat the same contents as unchanged (
['go', 'ts']and['ts', 'go']are the same). - Don't recreate the options array (
options) on every render; put it outside the component (or inuseMemo) as in the example above. The grid remembers a name lookup table per array, so a new array every time rebuilds the table on every lookup.
Chips in cells
The names of the chosen options are lined up as chips. Chips that don't fit in the column width are cut off, and hovering shows all names in a tooltip. Values not in the options become chips showing the value itself. When the column has a valueFormatter, its text is shown instead of chips.
Chip colors can be changed with tokens (the default is one color with a little of the cell text color mixed in).
.ssg-root {
--ssg-multi-select-chip-bg: #e0f2fe;
--ssg-multi-select-chip-text: #075985;
}Copy, paste and export
- The text for copy, CSV and export is the values joined with "、" (", " with the English texts
localeTextEn). Change the separator withmultiSelectSeparatorinlocaleText.clipboard: 'label'columns join names. Thevalueof cells ingetExportDatastays an array. - Pasted text is split at the separators (
multiSelectSeparatorand "、", ",", ","), trimmed, and matched to option values or names (values first; names first inclipboard: 'label'columns; text that doesn't match goes in as a value as is). For options whose name or value contains a separator ("A、B both"), if the following pieces joined together match the option, it's that option.
Filters and search
- A value-list column filter (
filterType: 'set';'auto'is a value list too) lists the options one by one and keeps rows that contain any of the chosen values. "(Blank)" is rows with nothing chosen. Exclude (mode: 'exclude') works the same way: it keeps rows that contain any value not excluded (it removes rows with only excluded values). - In columns whose options are decided only by
editorForRow(the column'seditorisn't a multi-select), the value list shows values instead of option names. To show names, write the options in the column'seditortoo. - Text conditions (contains / equals / starts with / ends with / blank) compare each value's name and value, and keep the row if any matches ("contains TypeScript" means rows with TypeScript chosen).
filterType: 'auto'is a value list too, and its condition field compares the same way. - Find in cells matches the names on screen, and the global filter matches both names and values (not across the boundary between values).
Keys
| Key | What happens |
|---|---|
↑ / ↓ / PageUp / PageDown | Move the highlight |
Space | Toggle the check of the highlighted option (in search columns, only after ↑ / ↓; right after typing it's a space character) |
Enter | Commit and move in the editorEnterMove direction (in search columns with typed text, add the highlighted option and clear the typed text) |
Tab / Shift+Tab | Commit and move right / left |
Escape | Cancel |
Backspace | With nothing typed, remove the last value |
Home / End | Start / end of the list in columns without search; the input's cursor in search columns |
| Printable keys | Prefix type-ahead on names in columns without search (IME-committed text isn't accepted; use search: true for options with Japanese names); narrowing by typing in search columns |
Ctrl / ⌘+Enter | Write to the whole selected range (excelShortcuts, see Excel keys) |
When focus moves outside the grid, it commits (the single select cancels), so a half-made choice isn't lost.
Narrowing by typing / fetching options from a server
With search: true (searching works even when omitted if there is loadOptions), an input for narrowing goes after the chips. It searches the same way as the searchable select editor: full-width and half-width, upper and lower case, and hiragana and katakana aren't distinguished, and description / searchText are searched too. Typed text isn't made into a value (it's only for narrowing). Enter with typed text adds the highlighted option and clears the typed text (without closing), and another Enter commits. loadOptions is written the same way (called once on open, then on every keystroke after waiting about 200ms, aborted through signal). Names of fetched options are used for the editor's chips; cell chips, copy, search and sorting use the names in options (values not in options show the value text. To show names in cells, also put the options for the values you use in options).
What this version doesn't support
There is no allowFreeText (text not in the options), fillRow, limit on how many can be chosen, or row grouping by each value. allowFreeText / fillRow have no effect if written, and rowGroup groups by each combination of chosen values (the name is the option names joined; rows with nothing chosen are "(Blank)". Each gives one warning in development).
With /lite
import { createSpreadsheetGrid, multiSelectFeature } from '@ishibashi0112/spreadsheet-grid/lite';
const Grid = createSpreadsheetGrid({ features: { multiSelect: multiSelectFeature } });Narrowing by typing (search / loadOptions) is in this part too, so selectSearchFeature isn't needed. Without the feature, the editor is a text input and cells show the names joined (one warning in development). The value shape, copy, paste, filters and sorting are in the core, so they stay the same.
Details are in the API reference.
Searchable select editor
Narrow options by typing with the select editor's search (also by reading or alias, options fetched from a server, filling other columns from the chosen option)
Time, date-time and calendar editors
The time / datetime editors and date's picker calendar (reading typed text, the calendar, a list of times, a time input for date-times)