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

페이지를 넘겨도 선택 유지Keep the selection across pages

선택은 행마다 붙은 고유 번호로 기억해서 다른 페이지로 넘어가도 고른 행이 그대로 남아요. 머리글 체크박스는 지금 보이는 페이지의 행만 다루고, 전체 개수는 기록 창에 알려 줘요.Selection is remembered by each row's unique number, so chosen rows stay chosen when you change page. The header checkbox only covers the visible page, and the log reports the running total.

활용Intermediate
직접 써 보기Live preview페이지를 넘겨도 선택 유지Keep the selection across pages

코드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="prevPage">이전 페이지</button>
    <button type="button" id="nextPage">다음 페이지</button>
    <button type="button" id="clear">선택 지우기</button>
  </div>
  <div id="grid" style="height: 500px"></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('prevPage').addEventListener('click', () => actions.prevPage(api));
document.getElementById('nextPage').addEventListener('click', () => actions.nextPage(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const tasks = [
  '견적서 작성',
  '계약서 검토',
  '샘플 발송',
  '시연 준비',
  '재고 점검',
  '세금계산서 발행',
];
export const options = {
  columns: [
    { id: 'id', title: '번호', kind: 'number', width: 70 },
    { id: 'name', title: '업무', width: 170 },
    { id: 'status', title: '상태', width: 90 },
  ],
  rows: Array.from({ length: 60 }, (_, i) => ({
    id: i + 1,
    name: `${tasks[i % 6]} ${Math.floor(i / 6) + 1}`,
    status: i % 3 === 0 ? '진행' : '완료',
  })),
  rowKey: 'id',
  selection: { mode: 'multiple', checkbox: true },
  pagination: { mode: 'client', pageSize: 10 },
};
// 선택은 행마다 붙은 고유 번호로 기억해서 페이지를 넘겨도 그대로 남아요. 머리글 체크박스는 지금 보이는 페이지만 다뤄요.
export function setup(api, log) {
  const offs = [
    api.on('selectionChanged', ({ selectedKeys }) => log({
      ko: `전체 ${selectedKeys.length}행 선택`,
      en: `${selectedKeys.length} rows selected in all`,
    })),
    api.on('pageChanged', ({ page }) => log({
      ko: `${page}페이지로 이동 · 전체 ${api.getSelectedKeys().length}행 선택 유지`,
      en: `Moved to page ${page} · ${api.getSelectedKeys().length} rows still selected in all`,
    })),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  nextPage: (api) => api.setPage(Math.min(api.getPage() + 1, api.getPageCount())),
  prevPage: (api) => api.setPage(Math.max(api.getPage() - 1, 1)),
  clear: (api) => api.clearSelection(),
};

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="prevPage">Previous page</button>
    <button type="button" id="nextPage">Next page</button>
    <button type="button" id="clear">Clear selection</button>
  </div>
  <div id="grid" style="height: 500px"></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('prevPage').addEventListener('click', () => actions.prevPage(api));
document.getElementById('nextPage').addEventListener('click', () => actions.nextPage(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const tasks = [
  'Write quote',
  'Review contract',
  'Ship samples',
  'Prepare demo',
  'Check inventory',
  'Issue invoice',
];
export const options = {
  columns: [
    { id: 'id', title: 'No.', kind: 'number', width: 70 },
    { id: 'name', title: 'Task', width: 190 },
    { id: 'status', title: 'Status', width: 100 },
  ],
  rows: Array.from({ length: 60 }, (_, i) => ({
    id: i + 1,
    name: `${tasks[i % 6]} ${Math.floor(i / 6) + 1}`,
    status: i % 3 === 0 ? 'In progress' : 'Done',
  })),
  rowKey: 'id',
  selection: { mode: 'multiple', checkbox: true },
  pagination: { mode: 'client', pageSize: 10 },
};
// Selection is remembered by each row's unique key, so it stays when you change pages. The header checkbox only handles the page you see now.
export function setup(api, log) {
  const offs = [
    api.on('selectionChanged', ({ selectedKeys }) => log(`${selectedKeys.length} rows selected in all`)),
    api.on('pageChanged', ({ page }) => log(`Moved to page ${page} · ${api.getSelectedKeys().length} rows still selected in all`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  nextPage: (api) => api.setPage(Math.min(api.getPage() + 1, api.getPageCount())),
  prevPage: (api) => api.setPage(Math.max(api.getPage() - 1, 1)),
  clear: (api) => api.clearSelection(),
};