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

여러 줄 칸 편집: textarea 편집기Edit several lines: the textarea editor

cellEditor: 'textarea'로 긴 글을 여러 줄 입력해요. Enter는 줄바꿈, Ctrl+Enter가 확정이고, 칸에는 첫 줄만 보이거나(wrap이면 전체) 보여요.cellEditor: 'textarea' edits long text over several lines. Enter adds a line, Ctrl+Enter confirms, and the cell shows the first line only (or all lines with wrap).

입문Beginner
직접 써 보기Live preview여러 줄 칸 편집: textarea 편집기Edit several lines: the textarea editor

코드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">
    <button type="button" id="editMemo">메모 편집</button>
  </div>
  <div id="grid" style="height: 300px"></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('editMemo').addEventListener('click', () => actions.editMemo(api));
example.js
const en = document.documentElement.dataset.lang === 'en';
const rows = [
  {
    id: 1,
    title: en ? 'Login is slow' : '로그인이 느려요',
    memo: en
      ? 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.'
      : '아침 9시쯤 5초 넘게 걸려요.\n스테이징도 같아요.\n로그는 첨부했어요.',
    notes: en ? 'Needs a check\nOwner: Kim' : '확인 필요\n담당: 김',
  },
  {
    id: 2,
    title: en ? 'A column is missing in the export' : '내보내기에서 컬럼이 빠져요',
    memo: en ? 'Only happens with a pinned column.' : '컬럼을 고정한 상태에서만 생겨요.',
    notes: '',
  },
  {
    id: 3,
    title: en ? 'Dark mode text is faint' : '다크 모드 글자가 흐려요',
    memo: '',
    notes: en ? 'Design review' : '디자인 검토',
  },
];
// cellEditor: 'textarea'는 여러 줄 편집기예요. Enter는 줄바꿈, Ctrl+Enter(Mac은 ⌘+Enter)가 확정이에요.
// 칸에는 첫 줄과 …만 보이고, wrap을 켠 컬럼은 줄바꿈 그대로 보여요.
export const options = {
  columns: [
    { id: 'title', title: en ? 'Title' : '제목', width: 190 },
    {
      id: 'memo',
      title: en ? 'Memo (first line only)' : '메모 (첫 줄만)',
      width: 260,
      editable: true,
      cellEditor: 'textarea',
      editorParams: { rows: 5, maxLength: 200, resize: true },
    },
    {
      id: 'notes',
      title: en ? 'Notes (line breaks kept)' : '비고 (줄바꿈 그대로)',
      width: 200,
      editable: true,
      wrap: true,
      cellEditor: 'textarea',
      editorParams: { rows: 3 },
    },
  ],
  rows,
  rowKey: 'id',
  rowHeight: 'auto',
  ariaLabel: en ? 'Multi-line editing' : '여러 줄 편집',
};
export function setup(api, log) {
  log({
    ko: '"메모" 칸을 더블클릭하세요. Enter는 줄바꿈, Ctrl+Enter는 확정, Esc는 취소, 다른 칸을 누르면 확정이에요.',
    en: 'Double-click a "메모" (memo) cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.',
  });
  const offs = [
    api.on('editCommitted', (e) => log({
      ko: `${e.rowKey}번 ${e.columnId}: ${String(e.newValue).split('\n').length}줄`,
      en: `Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`,
    })),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  editMemo: (api) => api.startEdit(1, 'memo'),
};

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">
    <button type="button" id="editMemo">Edit memo</button>
  </div>
  <div id="grid" style="height: 300px"></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('editMemo').addEventListener('click', () => actions.editMemo(api));
example.js
const rows = [
  {
    id: 1,
    title: 'Login is slow',
    memo: 'Takes over 5 seconds around 9 AM.\nSame on staging.\nLogs attached.',
    notes: 'Needs a check\nOwner: Kim',
  },
  {
    id: 2,
    title: 'A column is missing in the export',
    memo: 'Only happens with a pinned column.',
    notes: '',
  },
  {
    id: 3,
    title: 'Dark mode text is faint',
    memo: '',
    notes: 'Design review',
  },
];
// cellEditor: 'textarea' is a multi-line editor. Enter adds a line break, and Ctrl+Enter (⌘+Enter on Mac) confirms.
// The cell shows only the first line and …, and a column with wrap on shows the line breaks as they are.
export const options = {
  columns: [
    { id: 'title', title: 'Title', width: 190 },
    {
      id: 'memo',
      title: 'Memo (first line only)',
      width: 260,
      editable: true,
      cellEditor: 'textarea',
      editorParams: { rows: 5, maxLength: 200, resize: true },
    },
    {
      id: 'notes',
      title: 'Notes (line breaks kept)',
      width: 220,
      editable: true,
      wrap: true,
      cellEditor: 'textarea',
      editorParams: { rows: 3 },
    },
  ],
  rows,
  rowKey: 'id',
  rowHeight: 'auto',
  ariaLabel: 'Multi-line editing',
};
export function setup(api, log) {
  log('Double-click a "Memo" cell. Enter adds a line break, Ctrl+Enter confirms, Esc cancels, and clicking elsewhere confirms.');
  const offs = [
    api.on('editCommitted', (e) => log(`Row ${e.rowKey} ${e.columnId}: ${String(e.newValue).split('\n').length} lines`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  editMemo: (api) => api.startEdit(1, 'memo'),
};