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

셀을 고칠 때 내가 만든 컴포넌트 쓰기Use your own component as the cell editor

셀을 두 번 누르면 뜨는 입력창을 프레임워크의 컴포넌트로 바꿀 수 있어요. 여기서는 상태 칸에 선택 목록 컴포넌트를 붙이고, 고르는 즉시 편집을 끝내요. Enter·Esc·Tab은 표가 처리해서 컴포넌트는 값만 알려 주면 돼요. 위 화면은 같은 모양을 내장 선택 목록으로 보여 줘요.The input that opens on double-click can be replaced by a framework component. Here the status column gets a select component that ends the edit as soon as you pick. The grid handles Enter, Esc and Tab, so the component only reports the value. The preview shows the same look with the built-in select.

심화Advanced
직접 써 보기Live preview셀을 고칠 때 내가 만든 컴포넌트 쓰기Use your own component as the cell editor

실행 화면은 JavaScript 버전이에요. 아래 탭의 React·Vue·Angular 코드는 같은 예제를 각 프레임워크로 직접 쓴 코드예요.The preview runs the JavaScript version. The React, Vue, Angular tabs below hold the same example written for each framework.

코드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 id="grid" style="height: 360px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
export const STATUSES = ['대기', '진행', '완료'];
export const rows = [
  { id: 1, title: '견적서 보내기', status: '진행' },
  { id: 2, title: '계약서 검토', status: '대기' },
  { id: 3, title: '샘플 발송', status: '완료' },
  { id: 4, title: '재고 점검', status: '진행' },
];
/** 에디터를 붙이기 전의 컬럼이에요. 프레임워크 탭에서는 상태 컬럼에 컴포넌트 에디터를 붙여요. */
export const baseColumns = [
  { id: 'title', title: '업무', width: 220, editable: true, validation: { required: true } },
  { id: 'status', title: '상태', width: 150, editable: true },
];
// 이 화면(JavaScript 버전)은 내장 선택 목록 에디터를 써요.
export const options = {
  columns: baseColumns.map((column) => column.id === 'status'
    ? {
      ...column,
      kind: 'select',
      editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
    }
    : column),
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  return api.on('editCommitted', (e) => log({
    ko: `${e.columnId === 'status' ? '상태' : '업무'} 확정: '${String(e.newValue)}'`,
    en: `${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`,
  }));
}

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 id="grid" style="height: 360px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
example.js
export const STATUSES = ['Pending', 'Active', 'Done'];
export const rows = [
  { id: 1, title: 'Send the quote', status: 'Active' },
  { id: 2, title: 'Review the contract', status: 'Pending' },
  { id: 3, title: 'Ship samples', status: 'Done' },
  { id: 4, title: 'Check inventory', status: 'Active' },
];
/** Columns before the editor is attached. In the framework tabs a component editor is attached to the status column. */
export const baseColumns = [
  { id: 'title', title: 'Task', width: 220, editable: true, validation: { required: true } },
  { id: 'status', title: 'Status', width: 150, editable: true },
];
// This screen (JavaScript version) uses the built-in select editor.
export const options = {
  columns: baseColumns.map((column) => column.id === 'status'
    ? {
      ...column,
      kind: 'select',
      editorOptions: STATUSES.map((s) => ({ value: s, label: s })),
    }
    : column),
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  return api.on('editCommitted', (e) => log(`${e.columnId === 'status' ? 'Status' : 'Task'} confirmed: '${String(e.newValue)}'`));
}