본문으로 건너뛰기Skip to content
예제 첫화면Examples home

태그 칸: 여러 값을 꼬리표로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.

입문Beginner
직접 써 보기Live preview태그 칸: 여러 값을 꼬리표로Tag cells: several values as chips

코드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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<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>
main.js
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));
example.js
// 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)`,
    });
  },
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<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>
main.js
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));
example.js
// 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)`);
  },
};