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

여러 쓰기를 한 번에 되돌리기Undo many writes as one

beginBulkEdit과 endBulkEdit 사이의 쓰기(fillColumn, updateCells 등)를 되돌리기 한 단계로 묶어요. endBulkEdit({ commit: false })는 묶음을 한 번에 취소해요.Writes between beginBulkEdit and endBulkEdit (fillColumn, updateCells and so on) become one undo step. endBulkEdit({ commit: false }) cancels the whole group.

활용Intermediate
직접 써 보기Live preview여러 쓰기를 한 번에 되돌리기Undo many writes as one

코드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="commit">묶음 적용</button>
    <button type="button" id="cancel">묶음 취소</button>
    <button type="button" id="undo">되돌리기</button>
  </div>
  <div id="grid" style="height: 260px"></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('commit').addEventListener('click', () => actions.commit(api));
document.getElementById('cancel').addEventListener('click', () => actions.cancel(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));
example.js
const rows = [
  { id: 1, name: '작업 A', status: '대기', owner: '' },
  { id: 2, name: '작업 B', status: '대기', owner: '' },
  { id: 3, name: '작업 C', status: '대기', owner: '' },
];
// beginBulkEdit과 endBulkEdit 사이의 모든 쓰기가 되돌리기 한 단계가 돼요.
export const options = {
  columns: [
    { id: 'id', title: '번호', kind: 'number', width: 70 },
    { id: 'name', title: '이름', width: 110 },
    { id: 'status', title: '상태', width: 90, editable: true },
    { id: 'owner', title: '담당', width: 90, editable: true },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  const offs = [
    api.on('bulkEditStarted', () => log({ ko: '묶음 시작', en: 'Bulk started' })),
    api.on('bulkEditEnded', (e) => log({
      ko: `묶음 끝: ${e.count}칸, ${e.committed ? '확정' : '취소'}`,
      en: `Bulk ended: ${e.count} writes, ${e.committed ? 'committed' : 'cancelled'}`,
    })),
  ];
  return () => offs.forEach((off) => off());
}
const fill = (api) => {
  api.fillColumn('status', '진행');
  api.updateCells([1, 2], { owner: '나' });
};
export const actions = {
  commit: (api) => {
    api.beginBulkEdit();
    fill(api);
    api.endBulkEdit();
  },
  cancel: (api) => {
    api.beginBulkEdit();
    fill(api);
    api.endBulkEdit({ commit: false });
  },
  undo: (api) => void api.undo(),
};

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="commit">Apply group</button>
    <button type="button" id="cancel">Cancel group</button>
    <button type="button" id="undo">Undo</button>
  </div>
  <div id="grid" style="height: 260px"></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('commit').addEventListener('click', () => actions.commit(api));
document.getElementById('cancel').addEventListener('click', () => actions.cancel(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));
example.js
const rows = [
  { id: 1, name: 'Task A', status: 'Pending', owner: '' },
  { id: 2, name: 'Task B', status: 'Pending', owner: '' },
  { id: 3, name: 'Task C', status: 'Pending', owner: '' },
];
// Every write between beginBulkEdit and endBulkEdit becomes one undo step.
export const options = {
  columns: [
    { id: 'id', title: 'No.', kind: 'number', width: 70 },
    { id: 'name', title: 'Name', width: 110 },
    { id: 'status', title: 'Status', width: 90, editable: true },
    { id: 'owner', title: 'Owner', width: 90, editable: true },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  const offs = [
    api.on('bulkEditStarted', () => log('Bulk started')),
    api.on('bulkEditEnded', (e) => log(`Bulk ended: ${e.count} writes, ${e.committed ? 'committed' : 'cancelled'}`)),
  ];
  return () => offs.forEach((off) => off());
}
const fill = (api) => {
  api.fillColumn('status', 'In progress');
  api.updateCells([1, 2], { owner: 'Me' });
};
export const actions = {
  commit: (api) => {
    api.beginBulkEdit();
    fill(api);
    api.endBulkEdit();
  },
  cancel: (api) => {
    api.beginBulkEdit();
    fill(api);
    api.endBulkEdit({ commit: false });
  },
  undo: (api) => void api.undo(),
};