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

편집 중 키 이동을 내 방식으로 바꾸기Change how keys move while editing

editNav로 Enter 뒤 이동, Tab으로 편집 시작 여부, 읽기 전용 컬럼 건너뛰기, 편집 중 ↑↓ 확정, Backspace로 편집 시작을 고르고, 컬럼의 navigable로 키보드 이동에서 뺄 칸을 정해요.editNav picks where Enter goes, whether Tab starts an edit, skipping read-only columns, Up/Down commit and Backspace-to-edit; a column's navigable keeps it out of keyboard movement.

활용Intermediate
직접 써 보기Live preview편집 중 키 이동을 내 방식으로 바꾸기Change how keys move while editing

코드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="mode">
      <option value="basic" selected>기본</option>
      <option value="enter">Enter 뒤 아래로</option>
      <option value="sheet">엑셀처럼</option>
    </select>
    <button type="button" id="editQty">수량 편집</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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(api));
example.js
const rows = ['화이트보드', '보드 마카', '지우개', '자석 클립', '포스트잇'].map((item, i) => ({
  id: i + 1,
  item,
  qty: 2 + i,
  price: 1500 + i * 2500,
  note: '',
}));
// editNav는 편집 중 키 동작을 바꿔요. 기본은 그대로이고, 필요한 것만 켜요.
//  - enter: Enter로 확정한 뒤 한 칸 아래로
//  - skipReadonly: 방향키와 Tab이 읽기 전용 "품목" 컬럼을 건너뛰어요
//  - arrowCommit: 편집 중 ↑↓로 확정하고 이동(엑셀처럼 이어서 입력)
//  - backspaceStarts: Backspace로 칸을 비우며 편집 시작
// 컬럼의 navigable: false는 "메모"를 키보드 이동에서 빼요(마우스로는 고를 수 있어요).
const optionsFor = (mode) => ({
  columns: [
    { id: 'item', title: '품목', width: 120 },
    { id: 'qty', title: '수량', kind: 'number', width: 90, align: 'end', editable: true },
    { id: 'price', title: '단가', kind: 'number', width: 110, align: 'end', editable: true },
    { id: 'note', title: '메모 (키보드로 안 가요)', width: 190, editable: true, navigable: false },
  ],
  rows,
  rowKey: 'id',
  singleClickEdit: mode === 'sheet' ? 'all' : true,
  editNav: mode === 'basic'
    ? {}
    : mode === 'enter'
      ? { enter: 'down', tabStartsEdit: false }
      : { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options = optionsFor('basic');
export function setup(api, log) {
  log({
    ko: '"키 설정"을 바꿔 가며 수량 칸을 편집하고 Enter, Tab, ↑↓를 눌러 보세요.',
    en: 'Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.',
  });
  const offs = [
    api.on('editCommitted', (e) => log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`)),
    api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  mode: (api, value) => api.setOptions(optionsFor(value ?? 'basic')),
  editQty: (api) => api.startEdit(1, 'qty'),
};

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="Key mode" id="mode">
      <option value="basic" selected>Default</option>
      <option value="enter">Enter moves down</option>
      <option value="sheet">Spreadsheet style</option>
    </select>
    <button type="button" id="editQty">Edit quantity</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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('editQty').addEventListener('click', () => actions.editQty(api));
example.js
const rows = ['Whiteboard', 'Board markers', 'Eraser', 'Magnet clips', 'Sticky notes'].map((item, i) => ({
  id: i + 1,
  item,
  qty: 2 + i,
  price: 1.5 + i * 2.5,
  note: '',
}));
// editNav changes the key behavior while editing. The default is unchanged; turn on only what you need.
//  - enter: after committing with Enter, move one cell down
//  - skipReadonly: arrow keys and Tab skip the read-only "Item" column
//  - arrowCommit: Up/Down while editing commits and moves (keep typing like a spreadsheet)
//  - backspaceStarts: Backspace clears the cell and starts editing
// A column's navigable: false removes "Note" from keyboard movement (it can still be picked with the mouse).
const optionsFor = (mode) => ({
  columns: [
    { id: 'item', title: 'Item', width: 130 },
    { id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end', editable: true },
    { id: 'price', title: 'Price', kind: 'number', width: 110, align: 'end', editable: true },
    { id: 'note', title: 'Note (skipped by keys)', width: 190, editable: true, navigable: false },
  ],
  rows,
  rowKey: 'id',
  singleClickEdit: mode === 'sheet' ? 'all' : true,
  editNav: mode === 'basic'
    ? {}
    : mode === 'enter'
      ? { enter: 'down', tabStartsEdit: false }
      : { enter: 'down', skipReadonly: true, arrowCommit: true, backspaceStarts: true },
});
export const options = optionsFor('basic');
export function setup(api, log) {
  log('Switch the key mode, edit a quantity cell and press Enter, Tab and Up/Down.');
  const offs = [
    api.on('editCommitted', (e) => log(`${e.columnId}: ${String(e.oldValue)} → ${String(e.newValue)}`)),
    api.on('focusChanged', (e) => e.rowKey !== null && log(`focus #${e.rowKey} ${e.columnId}`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  mode: (api, value) => api.setOptions(optionsFor(value ?? 'basic')),
  editQty: (api) => api.startEdit(1, 'qty'),
};