태그 칸: 여러 값을 꼬리표로Tag cells: several values as chips
라벨이나 기술처럼 여러 값을 작은 꼬리표들로 보여 줘요. 많으면 "+2"처럼 접고, 구분 글자로 나눈 글자도 태그가 돼요.Show several values such as labels or skills as small chips. Extra ones fold into "+2", and text split by a separator also becomes tags.
코드Code
탭을 골라 코드를 복사하세요. 위 화면은 이 코드를 그대로 실행한 결과예요.Pick a tab and copy the code. The preview above runs exactly this code.
이 화면은 새 모양 옵션을 켠 모양이에요: density: 'spacious', iconStyle: 'soft', motion: true (코드에 없으면 기본 모양으로 보여요)This preview has the new-look options on: density: 'spacious', iconStyle: 'soft', motion: true (without them in your code you get the default look)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<div id="app">
<div class="toolbar">
<select aria-label="한 칸에 보일 개수" id="max">
<option value="2">2개</option>
<option value="3" selected>3개</option>
<option value="99">모두 보기</option>
</select>
<button type="button" id="add">3번 줄에 라벨 더하기</button>
</div>
<div id="grid" style="height: 280px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('max').addEventListener('change', (event) => actions.max(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));// cellRenderer: 'tags'는 값을 작은 꼬리표(태그)들로 그려요. 값은 글자 배열이거나, 구분 글자로 나눈 글자 하나예요.
// 빈 항목은 빼고, max개를 넘으면 "+N"으로 접어요(+N에 마우스를 올리면 접힌 태그가 나와요).
const rows = [
{
id: 1,
title: '내보내기에서 마지막 줄이 빠져요',
labels: ['버그', '내보내기'],
skills: 'TypeScript; React; 테스트; CI',
},
{
id: 2,
title: '어두운 화면의 머리글',
labels: ['버그', '테마', '접근성', '회귀', '긴급'],
skills: 'Vue;Node',
},
{ id: 3, title: '태그 칸 만들기', labels: ['기능'], skills: 'Angular; RxJS; 접근성' },
{ id: 4, title: '로드맵 쓰기', labels: [], skills: '디자인 시스템' },
{ id: 5, title: '정리 안 된 입력', labels: [' 문서 ', '', '운영'], skills: '' },
];
let max = 3;
const columns = () => [
{ id: 'title', title: '이슈', width: 200 },
{
id: 'labels',
title: '라벨(배열)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: '기술(; 로 나눈 글자)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
export const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
export function setup(api, log) {
say = log;
max = 3;
log({
ko: '5개짜리 줄은 3개만 보이고 나머지는 "+2"로 접혀요. "+2"를 누르면 접힌 태그가 여기에 나와요.',
en: 'A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.',
});
// 마우스를 올리지 못하는 화면에서도 접힌 태그를 읽을 수 있게, "+N"을 누르면 기록에 풀어 적어 줘요.
return api.on('cellClicked', (e) => {
const more = e.event.target?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills'))
return;
const raw = e.row[e.columnId];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
export const actions = {
max: (api, value) => {
max = Number(value ?? '3');
api.setColumns(columns());
say({ ko: `한 칸에 태그를 ${max}개까지 보여요.`, en: `Showing up to ${max} tags in a cell.` });
},
add: (api) => {
const row = api.getRowByKey(3);
if (!row)
return;
api.updateRows([{ ...row, labels: [...row.labels, `새 라벨 ${row.labels.length + 1}`] }]);
say({
ko: `3번 줄에 라벨을 하나 더했어요. (지금 ${row.labels.length + 1}개)`,
en: `Added one more label to row 3. (${row.labels.length + 1} now)`,
});
},
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>태그 칸: 여러 값을 꼬리표로</title>
</head>
<body>
<div class="toolbar">
<select aria-label="한 칸에 보일 개수" id="max">
<option value="2">2개</option>
<option value="3" selected>3개</option>
<option value="99">모두 보기</option>
</select>
<button type="button" id="add">3번 줄에 라벨 더하기</button>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// cellRenderer: 'tags'는 값을 작은 꼬리표(태그)들로 그려요. 값은 글자 배열이거나, 구분 글자로 나눈 글자 하나예요.
// 빈 항목은 빼고, max개를 넘으면 "+N"으로 접어요(+N에 마우스를 올리면 접힌 태그가 나와요).
const rows = [
{
id: 1,
title: '내보내기에서 마지막 줄이 빠져요',
labels: ['버그', '내보내기'],
skills: 'TypeScript; React; 테스트; CI',
},
{
id: 2,
title: '어두운 화면의 머리글',
labels: ['버그', '테마', '접근성', '회귀', '긴급'],
skills: 'Vue;Node',
},
{ id: 3, title: '태그 칸 만들기', labels: ['기능'], skills: 'Angular; RxJS; 접근성' },
{ id: 4, title: '로드맵 쓰기', labels: [], skills: '디자인 시스템' },
{ id: 5, title: '정리 안 된 입력', labels: [' 문서 ', '', '운영'], skills: '' },
];
let max = 3;
const columns = () => [
{ id: 'title', title: '이슈', width: 200 },
{
id: 'labels',
title: '라벨(배열)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: '기술(; 로 나눈 글자)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
function setup(api, log) {
say = log;
max = 3;
log({
ko: '5개짜리 줄은 3개만 보이고 나머지는 "+2"로 접혀요. "+2"를 누르면 접힌 태그가 여기에 나와요.',
en: 'A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.',
});
// 마우스를 올리지 못하는 화면에서도 접힌 태그를 읽을 수 있게, "+N"을 누르면 기록에 풀어 적어 줘요.
return api.on('cellClicked', (e) => {
const more = e.event.target?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills'))
return;
const raw = e.row[e.columnId];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
const actions = {
max: (api, value) => {
max = Number(value ?? '3');
api.setColumns(columns());
say({ ko: `한 칸에 태그를 ${max}개까지 보여요.`, en: `Showing up to ${max} tags in a cell.` });
},
add: (api) => {
const row = api.getRowByKey(3);
if (!row)
return;
api.updateRows([{ ...row, labels: [...row.labels, `새 라벨 ${row.labels.length + 1}`] }]);
say({
ko: `3번 줄에 라벨을 하나 더했어요. (지금 ${row.labels.length + 1}개)`,
en: `Added one more label to row 3. (${row.labels.length + 1} now)`,
});
},
};
options.ariaLabel = "태그 칸: 여러 값을 꼬리표로";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('max').addEventListener('change', (event) => actions.max(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="한 칸에 보일 개수"
disabled={!api}
onChange={(event) => api && actions.max(api, event.target.value)}
>
<option value="2">2개</option>
<option value="3">3개</option>
<option value="99">모두 보기</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.add(api)}
>3번 줄에 라벨 더하기</button>
</div>
<Grid style={{ height: 280 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
labels: string[];
skills: string;
}
// cellRenderer: 'tags'는 값을 작은 꼬리표(태그)들로 그려요. 값은 글자 배열이거나, 구분 글자로 나눈 글자 하나예요.
// 빈 항목은 빼고, max개를 넘으면 "+N"으로 접어요(+N에 마우스를 올리면 접힌 태그가 나와요).
const rows: Row[] = [
{
id: 1,
title: '내보내기에서 마지막 줄이 빠져요',
labels: ['버그', '내보내기'],
skills: 'TypeScript; React; 테스트; CI',
},
{
id: 2,
title: '어두운 화면의 머리글',
labels: ['버그', '테마', '접근성', '회귀', '긴급'],
skills: 'Vue;Node',
},
{ id: 3, title: '태그 칸 만들기', labels: ['기능'], skills: 'Angular; RxJS; 접근성' },
{ id: 4, title: '로드맵 쓰기', labels: [], skills: '디자인 시스템' },
{ id: 5, title: '정리 안 된 입력', labels: [' 문서 ', '', '운영'], skills: '' },
];
let max = 3;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'title', title: '이슈', width: 200 },
{
id: 'labels',
title: '라벨(배열)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: '기술(; 로 나눈 글자)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
max = 3;
log({
ko: '5개짜리 줄은 3개만 보이고 나머지는 "+2"로 접혀요. "+2"를 누르면 접힌 태그가 여기에 나와요.',
en: 'A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.',
});
// 마우스를 올리지 못하는 화면에서도 접힌 태그를 읽을 수 있게, "+N"을 누르면 기록에 풀어 적어 줘요.
return api.on('cellClicked', (e) => {
const more = (e.event.target as HTMLElement | null)?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills')) return;
const raw = e.row[e.columnId as 'labels' | 'skills'];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
export const actions = {
max: (api: GridApi<Row>, value?: string) => {
max = Number(value ?? '3');
api.setColumns(columns());
say({ ko: `한 칸에 태그를 ${max}개까지 보여요.`, en: `Showing up to ${max} tags in a cell.` });
},
add: (api: GridApi<Row>) => {
const row = api.getRowByKey(3);
if (!row) return;
api.updateRows([{ ...row, labels: [...row.labels, `새 라벨 ${row.labels.length + 1}`] }]);
say({
ko: `3번 줄에 라벨을 하나 더했어요. (지금 ${row.labels.length + 1}개)`,
en: `Added one more label to row 3. (${row.labels.length + 1} now)`,
});
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="한 칸에 보일 개수"
:disabled="!api"
@change="api && actions.max(api, ($event.target as HTMLSelectElement).value)"
>
<option value="2">2개</option>
<option value="3" selected>3개</option>
<option value="99">모두 보기</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.add(api)">3번 줄에 라벨 더하기</button>
</div>
<Grid style="height: 280px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
labels: string[];
skills: string;
}
// cellRenderer: 'tags'는 값을 작은 꼬리표(태그)들로 그려요. 값은 글자 배열이거나, 구분 글자로 나눈 글자 하나예요.
// 빈 항목은 빼고, max개를 넘으면 "+N"으로 접어요(+N에 마우스를 올리면 접힌 태그가 나와요).
const rows: Row[] = [
{
id: 1,
title: '내보내기에서 마지막 줄이 빠져요',
labels: ['버그', '내보내기'],
skills: 'TypeScript; React; 테스트; CI',
},
{
id: 2,
title: '어두운 화면의 머리글',
labels: ['버그', '테마', '접근성', '회귀', '긴급'],
skills: 'Vue;Node',
},
{ id: 3, title: '태그 칸 만들기', labels: ['기능'], skills: 'Angular; RxJS; 접근성' },
{ id: 4, title: '로드맵 쓰기', labels: [], skills: '디자인 시스템' },
{ id: 5, title: '정리 안 된 입력', labels: [' 문서 ', '', '운영'], skills: '' },
];
let max = 3;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'title', title: '이슈', width: 200 },
{
id: 'labels',
title: '라벨(배열)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: '기술(; 로 나눈 글자)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
max = 3;
log({
ko: '5개짜리 줄은 3개만 보이고 나머지는 "+2"로 접혀요. "+2"를 누르면 접힌 태그가 여기에 나와요.',
en: 'A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.',
});
// 마우스를 올리지 못하는 화면에서도 접힌 태그를 읽을 수 있게, "+N"을 누르면 기록에 풀어 적어 줘요.
return api.on('cellClicked', (e) => {
const more = (e.event.target as HTMLElement | null)?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills')) return;
const raw = e.row[e.columnId as 'labels' | 'skills'];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
export const actions = {
max: (api: GridApi<Row>, value?: string) => {
max = Number(value ?? '3');
api.setColumns(columns());
say({ ko: `한 칸에 태그를 ${max}개까지 보여요.`, en: `Showing up to ${max} tags in a cell.` });
},
add: (api: GridApi<Row>) => {
const row = api.getRowByKey(3);
if (!row) return;
api.updateRows([{ ...row, labels: [...row.labels, `새 라벨 ${row.labels.length + 1}`] }]);
say({
ko: `3번 줄에 라벨을 하나 더했어요. (지금 ${row.labels.length + 1}개)`,
en: `Added one more label to row 3. (${row.labels.length + 1} now)`,
});
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="한 칸에 보일 개수"
[disabled]="!api"
(change)="api && actions.max(api, $any($event.target).value)"
>
<option value="2">2개</option>
<option value="3" selected>3개</option>
<option value="99">모두 보기</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.add(api)"
>3번 줄에 라벨 더하기</button>
</div>
<mx-grid style="height: 280px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
title: string;
labels: string[];
skills: string;
}
// cellRenderer: 'tags'는 값을 작은 꼬리표(태그)들로 그려요. 값은 글자 배열이거나, 구분 글자로 나눈 글자 하나예요.
// 빈 항목은 빼고, max개를 넘으면 "+N"으로 접어요(+N에 마우스를 올리면 접힌 태그가 나와요).
const rows: Row[] = [
{
id: 1,
title: '내보내기에서 마지막 줄이 빠져요',
labels: ['버그', '내보내기'],
skills: 'TypeScript; React; 테스트; CI',
},
{
id: 2,
title: '어두운 화면의 머리글',
labels: ['버그', '테마', '접근성', '회귀', '긴급'],
skills: 'Vue;Node',
},
{ id: 3, title: '태그 칸 만들기', labels: ['기능'], skills: 'Angular; RxJS; 접근성' },
{ id: 4, title: '로드맵 쓰기', labels: [], skills: '디자인 시스템' },
{ id: 5, title: '정리 안 된 입력', labels: [' 문서 ', '', '운영'], skills: '' },
];
let max = 3;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'title', title: '이슈', width: 200 },
{
id: 'labels',
title: '라벨(배열)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: '기술(; 로 나눈 글자)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
max = 3;
log({
ko: '5개짜리 줄은 3개만 보이고 나머지는 "+2"로 접혀요. "+2"를 누르면 접힌 태그가 여기에 나와요.',
en: 'A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.',
});
// 마우스를 올리지 못하는 화면에서도 접힌 태그를 읽을 수 있게, "+N"을 누르면 기록에 풀어 적어 줘요.
return api.on('cellClicked', (e) => {
const more = (e.event.target as HTMLElement | null)?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills')) return;
const raw = e.row[e.columnId as 'labels' | 'skills'];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
export const actions = {
max: (api: GridApi<Row>, value?: string) => {
max = Number(value ?? '3');
api.setColumns(columns());
say({ ko: `한 칸에 태그를 ${max}개까지 보여요.`, en: `Showing up to ${max} tags in a cell.` });
},
add: (api: GridApi<Row>) => {
const row = api.getRowByKey(3);
if (!row) return;
api.updateRows([{ ...row, labels: [...row.labels, `새 라벨 ${row.labels.length + 1}`] }]);
say({
ko: `3번 줄에 라벨을 하나 더했어요. (지금 ${row.labels.length + 1}개)`,
en: `Added one more label to row 3. (${row.labels.length + 1} now)`,
});
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Tags per cell" id="max">
<option value="2">2</option>
<option value="3" selected>3</option>
<option value="99">All</option>
</select>
<button type="button" id="add">Add a label to row 3</button>
</div>
<div id="grid" style="height: 280px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('max').addEventListener('change', (event) => actions.max(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));// cellRenderer: 'tags' draws the value as small tags. The value is an array of strings, or one string split by a separator.
// Empty items are dropped, and anything beyond max folds into "+N" (hover "+N" to see the folded tags).
const rows = [
{
id: 1,
title: 'Last row is missing from the export',
labels: ['bug', 'export'],
skills: 'TypeScript; React; Testing; CI',
},
{
id: 2,
title: 'Header in dark mode',
labels: ['bug', 'theme', 'a11y', 'regression', 'urgent'],
skills: 'Vue;Node',
},
{
id: 3,
title: 'Build the tag cell',
labels: ['feature'],
skills: 'Angular; RxJS; Accessibility',
},
{ id: 4, title: 'Write the roadmap', labels: [], skills: 'Design system' },
{ id: 5, title: 'Messy input', labels: [' docs ', '', 'ops'], skills: '' },
];
let max = 3;
const columns = () => [
{ id: 'title', title: 'Issue', width: 240 },
{
id: 'labels',
title: 'Labels (array)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: 'Skills (string split by ;)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
export const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
export function setup(api, log) {
say = log;
max = 3;
log('A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.');
// So folded tags can be read on screens without hover, clicking "+N" writes them out in the log.
return api.on('cellClicked', (e) => {
const more = e.event.target?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills'))
return;
const raw = e.row[e.columnId];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
export const actions = {
max: (api, value) => {
max = Number(value ?? '3');
api.setColumns(columns());
say(`Showing up to ${max} tags in a cell.`);
},
add: (api) => {
const row = api.getRowByKey(3);
if (!row)
return;
api.updateRows([{ ...row, labels: [...row.labels, `New label ${row.labels.length + 1}`] }]);
say(`Added one more label to row 3. (${row.labels.length + 1} now)`);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Tag cells: several values as chips</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Tags per cell" id="max">
<option value="2">2</option>
<option value="3" selected>3</option>
<option value="99">All</option>
</select>
<button type="button" id="add">Add a label to row 3</button>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// cellRenderer: 'tags' draws the value as small tags. The value is an array of strings, or one string split by a separator.
// Empty items are dropped, and anything beyond max folds into "+N" (hover "+N" to see the folded tags).
const rows = [
{
id: 1,
title: 'Last row is missing from the export',
labels: ['bug', 'export'],
skills: 'TypeScript; React; Testing; CI',
},
{
id: 2,
title: 'Header in dark mode',
labels: ['bug', 'theme', 'a11y', 'regression', 'urgent'],
skills: 'Vue;Node',
},
{
id: 3,
title: 'Build the tag cell',
labels: ['feature'],
skills: 'Angular; RxJS; Accessibility',
},
{ id: 4, title: 'Write the roadmap', labels: [], skills: 'Design system' },
{ id: 5, title: 'Messy input', labels: [' docs ', '', 'ops'], skills: '' },
];
let max = 3;
const columns = () => [
{ id: 'title', title: 'Issue', width: 240 },
{
id: 'labels',
title: 'Labels (array)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: 'Skills (string split by ;)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
const options = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
function setup(api, log) {
say = log;
max = 3;
log('A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.');
// So folded tags can be read on screens without hover, clicking "+N" writes them out in the log.
return api.on('cellClicked', (e) => {
const more = e.event.target?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills'))
return;
const raw = e.row[e.columnId];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
const actions = {
max: (api, value) => {
max = Number(value ?? '3');
api.setColumns(columns());
say(`Showing up to ${max} tags in a cell.`);
},
add: (api) => {
const row = api.getRowByKey(3);
if (!row)
return;
api.updateRows([{ ...row, labels: [...row.labels, `New label ${row.labels.length + 1}`] }]);
say(`Added one more label to row 3. (${row.labels.length + 1} now)`);
},
};
options.ariaLabel = "Tag cells: several values as chips";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('max').addEventListener('change', (event) => actions.max(api, event.target.value));
document.getElementById('add').addEventListener('click', () => actions.add(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Tags per cell"
disabled={!api}
onChange={(event) => api && actions.max(api, event.target.value)}
>
<option value="2">2</option>
<option value="3">3</option>
<option value="99">All</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.add(api)}
>Add a label to row 3</button>
</div>
<Grid style={{ height: 280 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
title: string;
labels: string[];
skills: string;
}
// cellRenderer: 'tags' draws the value as small tags. The value is an array of strings, or one string split by a separator.
// Empty items are dropped, and anything beyond max folds into "+N" (hover "+N" to see the folded tags).
const rows: Row[] = [
{
id: 1,
title: 'Last row is missing from the export',
labels: ['bug', 'export'],
skills: 'TypeScript; React; Testing; CI',
},
{
id: 2,
title: 'Header in dark mode',
labels: ['bug', 'theme', 'a11y', 'regression', 'urgent'],
skills: 'Vue;Node',
},
{
id: 3,
title: 'Build the tag cell',
labels: ['feature'],
skills: 'Angular; RxJS; Accessibility',
},
{ id: 4, title: 'Write the roadmap', labels: [], skills: 'Design system' },
{ id: 5, title: 'Messy input', labels: [' docs ', '', 'ops'], skills: '' },
];
let max = 3;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'title', title: 'Issue', width: 240 },
{
id: 'labels',
title: 'Labels (array)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: 'Skills (string split by ;)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
max = 3;
log(
'A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.',
);
// So folded tags can be read on screens without hover, clicking "+N" writes them out in the log.
return api.on('cellClicked', (e) => {
const more = (e.event.target as HTMLElement | null)?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills')) return;
const raw = e.row[e.columnId as 'labels' | 'skills'];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
export const actions = {
max: (api: GridApi<Row>, value?: string) => {
max = Number(value ?? '3');
api.setColumns(columns());
say(`Showing up to ${max} tags in a cell.`);
},
add: (api: GridApi<Row>) => {
const row = api.getRowByKey(3);
if (!row) return;
api.updateRows([{ ...row, labels: [...row.labels, `New label ${row.labels.length + 1}`] }]);
say(`Added one more label to row 3. (${row.labels.length + 1} now)`);
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Tags per cell"
:disabled="!api"
@change="api && actions.max(api, ($event.target as HTMLSelectElement).value)"
>
<option value="2">2</option>
<option value="3" selected>3</option>
<option value="99">All</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.add(api)">Add a label to row 3</button>
</div>
<Grid style="height: 280px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
title: string;
labels: string[];
skills: string;
}
// cellRenderer: 'tags' draws the value as small tags. The value is an array of strings, or one string split by a separator.
// Empty items are dropped, and anything beyond max folds into "+N" (hover "+N" to see the folded tags).
const rows: Row[] = [
{
id: 1,
title: 'Last row is missing from the export',
labels: ['bug', 'export'],
skills: 'TypeScript; React; Testing; CI',
},
{
id: 2,
title: 'Header in dark mode',
labels: ['bug', 'theme', 'a11y', 'regression', 'urgent'],
skills: 'Vue;Node',
},
{
id: 3,
title: 'Build the tag cell',
labels: ['feature'],
skills: 'Angular; RxJS; Accessibility',
},
{ id: 4, title: 'Write the roadmap', labels: [], skills: 'Design system' },
{ id: 5, title: 'Messy input', labels: [' docs ', '', 'ops'], skills: '' },
];
let max = 3;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'title', title: 'Issue', width: 240 },
{
id: 'labels',
title: 'Labels (array)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: 'Skills (string split by ;)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
max = 3;
log(
'A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.',
);
// So folded tags can be read on screens without hover, clicking "+N" writes them out in the log.
return api.on('cellClicked', (e) => {
const more = (e.event.target as HTMLElement | null)?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills')) return;
const raw = e.row[e.columnId as 'labels' | 'skills'];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
export const actions = {
max: (api: GridApi<Row>, value?: string) => {
max = Number(value ?? '3');
api.setColumns(columns());
say(`Showing up to ${max} tags in a cell.`);
},
add: (api: GridApi<Row>) => {
const row = api.getRowByKey(3);
if (!row) return;
api.updateRows([{ ...row, labels: [...row.labels, `New label ${row.labels.length + 1}`] }]);
say(`Added one more label to row 3. (${row.labels.length + 1} now)`);
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Tags per cell"
[disabled]="!api"
(change)="api && actions.max(api, $any($event.target).value)"
>
<option value="2">2</option>
<option value="3" selected>3</option>
<option value="99">All</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.add(api)"
>Add a label to row 3</button>
</div>
<mx-grid style="height: 280px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
title: string;
labels: string[];
skills: string;
}
// cellRenderer: 'tags' draws the value as small tags. The value is an array of strings, or one string split by a separator.
// Empty items are dropped, and anything beyond max folds into "+N" (hover "+N" to see the folded tags).
const rows: Row[] = [
{
id: 1,
title: 'Last row is missing from the export',
labels: ['bug', 'export'],
skills: 'TypeScript; React; Testing; CI',
},
{
id: 2,
title: 'Header in dark mode',
labels: ['bug', 'theme', 'a11y', 'regression', 'urgent'],
skills: 'Vue;Node',
},
{
id: 3,
title: 'Build the tag cell',
labels: ['feature'],
skills: 'Angular; RxJS; Accessibility',
},
{ id: 4, title: 'Write the roadmap', labels: [], skills: 'Design system' },
{ id: 5, title: 'Messy input', labels: [' docs ', '', 'ops'], skills: '' },
];
let max = 3;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'title', title: 'Issue', width: 240 },
{
id: 'labels',
title: 'Labels (array)',
width: 240,
cellRenderer: 'tags',
cellRendererParams: { max },
},
{
id: 'skills',
title: 'Skills (string split by ;)',
width: 260,
cellRenderer: 'tags',
cellRendererParams: { separator: ';', max },
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows,
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
max = 3;
log(
'A row with 5 tags shows only 3 and folds the rest into "+2". Click "+2" and the folded tags appear here.',
);
// So folded tags can be read on screens without hover, clicking "+N" writes them out in the log.
return api.on('cellClicked', (e) => {
const more = (e.event.target as HTMLElement | null)?.closest('.mxg-tag-more');
if (!more || (e.columnId !== 'labels' && e.columnId !== 'skills')) return;
const raw = e.row[e.columnId as 'labels' | 'skills'];
const all = (Array.isArray(raw) ? raw : raw.split(';')).map((t) => t.trim()).filter(Boolean);
log(`${e.row.title}: ${all.slice(max).join(', ')}`);
});
}
export const actions = {
max: (api: GridApi<Row>, value?: string) => {
max = Number(value ?? '3');
api.setColumns(columns());
say(`Showing up to ${max} tags in a cell.`);
},
add: (api: GridApi<Row>) => {
const row = api.getRowByKey(3);
if (!row) return;
api.updateRows([{ ...row, labels: [...row.labels, `New label ${row.labels.length + 1}`] }]);
say(`Added one more label to row 3. (${row.labels.length + 1} now)`);
},
};