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

입력할 때마다 오는 editInput 이벤트The editInput event on every keystroke

editInput은 편집기의 입력칸 글자가 바뀔 때마다 rowKey·columnId·value와 함께 와요. value는 해석·검증 전 글자라서 글자 수 표시나 실시간 검색에 알맞아요.editInput arrives whenever the editor's text changes, with rowKey, columnId and value. The value is the text before parsing and validation, which suits a character counter or live search.

활용Intermediate
직접 써 보기Live preview입력할 때마다 오는 editInput 이벤트The editInput event on every keystroke

코드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="editTitle">제목 편집</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('editTitle').addEventListener('click', () => actions.editTitle(api));
example.js
const en = document.documentElement.dataset.lang === 'en';
export const options = {
  columns: [
    { id: 'title', title: en ? 'Title' : '제목', width: 150, editable: true },
    {
      id: 'memo',
      title: en ? 'Memo' : '메모',
      width: 220,
      editable: true,
      cellEditor: 'textarea',
      editorParams: { rows: 3 },
    },
    {
      id: 'code',
      title: en ? 'Code' : '코드',
      width: 130,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: 'AA-####' },
    },
  ],
  rows: [
    { id: 1, title: en ? 'First' : '첫 번째', memo: '', code: 'AB-1234' },
    {
      id: 2,
      title: en ? 'Second' : '두 번째',
      memo: en ? 'Multi\nline memo' : '여러 줄\n메모',
      code: '',
    },
  ],
  rowKey: 'id',
  ariaLabel: en ? 'Input events' : '입력 이벤트',
};
let count = 0;
// editInput은 입력칸의 글자가 바뀔 때마다 { rowKey, columnId, value }로 와요. value는 아직 해석·검증 전의 글자예요.
// 글자 수 표시나 실시간 검색처럼 확정 전에 반응해야 할 때 써요. 체크박스·선택·날짜 선택기는 고르면 바로 확정돼서 오지 않아요.
export function setup(api, log) {
  count = 0;
  log({
    ko: '제목 칸을 더블클릭하고 글자를 쳐 보세요. 칠 때마다 editInput이 와요.',
    en: 'Double-click a title cell and type. editInput arrives on every keystroke.',
  });
  const offs = [
    api.on('editInput', (e) => {
      count += 1;
      log({
        ko: `#${count} ${e.rowKey}번 ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length}자)`,
        en: `#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`,
      });
    }),
    api.on('editCommitted', (e) => log({ ko: `확정: ${String(e.newValue)}`, en: `Committed: ${String(e.newValue)}` })),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  editTitle: (api) => api.startEdit(1, 'title'),
};

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="editTitle">Edit title</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('editTitle').addEventListener('click', () => actions.editTitle(api));
example.js
export const options = {
  columns: [
    { id: 'title', title: 'Title', width: 150, editable: true },
    {
      id: 'memo',
      title: 'Memo',
      width: 220,
      editable: true,
      cellEditor: 'textarea',
      editorParams: { rows: 3 },
    },
    {
      id: 'code',
      title: 'Code',
      width: 130,
      editable: true,
      cellEditor: 'mask',
      editorParams: { pattern: 'AA-####' },
    },
  ],
  rows: [
    { id: 1, title: 'First', memo: '', code: 'AB-1234' },
    { id: 2, title: 'Second', memo: 'Multi\nline memo', code: '' },
  ],
  rowKey: 'id',
  ariaLabel: 'Input events',
};
let count = 0;
// editInput arrives as { rowKey, columnId, value } every time the text in the input changes. value is the raw text, before parsing and validation.
// Use it to react before commit, such as a character counter or live search. Checkboxes, selects and date pickers commit as soon as you pick, so they do not send it.
export function setup(api, log) {
  count = 0;
  log('Double-click a title cell and type. editInput arrives on every keystroke.');
  const offs = [
    api.on('editInput', (e) => {
      count += 1;
      log(`#${count} row ${e.rowKey} ${e.columnId}: "${String(e.value).replace(/\n/g, '↵')}" (${String(e.value).length} chars)`);
    }),
    api.on('editCommitted', (e) => log(`Committed: ${String(e.newValue)}`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  editTitle: (api) => api.startEdit(1, 'title'),
};