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

페이저의 문구와 구성을 내 방식으로Shape the pager text and layout

summary로 요약 문구를, pageButtons로 번호 칸 수를, parts로 보일 부분과 순서를 정해요. autoPageSize는 그리드 높이에 맞춰 한 쪽의 행 수를 정하고, nextPage·lastPage 같은 메서드로 코드에서 쪽을 옮겨요.summary writes the summary text, pageButtons sets the number slots and parts chooses which parts show and in what order. autoPageSize fits the rows per page to the grid height, and nextPage, lastPage and friends move pages from code.

활용Intermediate
직접 써 보기Live preview페이저의 문구와 구성을 내 방식으로Shape the pager text and layout

코드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="layout">
      <option value="default" selected>기본</option>
      <option value="compact">간단하게</option>
      <option value="auto">높이에 맞춤</option>
    </select>
    <button type="button" id="firstPage">처음 쪽</button>
    <button type="button" id="prevPage">이전 쪽</button>
    <button type="button" id="nextPage">다음 쪽</button>
    <button type="button" id="lastPage">마지막 쪽</button>
  </div>
  <div id="grid" style="height: 340px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('layout').addEventListener('change', (event) => actions.layout(api, event.target.value));
document.getElementById('firstPage').addEventListener('click', () => actions.firstPage(api));
document.getElementById('prevPage').addEventListener('click', () => actions.prevPage(api));
document.getElementById('nextPage').addEventListener('click', () => actions.nextPage(api));
document.getElementById('lastPage').addEventListener('click', () => actions.lastPage(api));
example.js
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const rows = Array.from({ length: 237 }, (_, i) => ({
  id: i + 1,
  name: `${L('상품', 'Item')} ${i + 1}`,
  qty: (i * 7) % 50,
}));
// summary로 요약 문구를, pageButtons로 번호 칸 수를, parts로 보일 부분과 순서를 정해요.
// autoPageSize를 켜면 그리드 높이에 맞춰 한 쪽의 행 수가 정해져요(숫자 rowHeight가 필요해요).
const optionsFor = (layout) => ({
  columns: [
    { id: 'id', title: 'ID', kind: 'number', width: 70 },
    { id: 'name', title: L('이름', 'Name'), width: 160 },
    { id: 'qty', title: L('수량', 'Qty'), kind: 'number', width: 90, align: 'end' },
  ],
  rows,
  rowKey: 'id',
  rowHeight: 32,
  pagination: layout === 'default'
    ? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
    : layout === 'compact'
      ? {
        mode: 'client',
        pageSize: 10,
        pageButtons: 5,
        parts: ['nav', 'summary'],
        summary: (info) => L(`${info.page}/${info.pageCount}쪽 · 총 ${info.totalRows}건`, `Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`),
      }
      : { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options = optionsFor('default');
export const actions = {
  layout: (api, value) => api.setOptions(optionsFor((value ?? 'default'))),
  firstPage: (api) => api.firstPage(),
  prevPage: (api) => api.prevPage(),
  nextPage: (api) => api.nextPage(),
  lastPage: (api) => api.lastPage(),
};

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="Pager layout" id="layout">
      <option value="default" selected>Default</option>
      <option value="compact">Compact</option>
      <option value="auto">Fit to height</option>
    </select>
    <button type="button" id="firstPage">First page</button>
    <button type="button" id="prevPage">Previous page</button>
    <button type="button" id="nextPage">Next page</button>
    <button type="button" id="lastPage">Last page</button>
  </div>
  <div id="grid" style="height: 340px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('layout').addEventListener('change', (event) => actions.layout(api, event.target.value));
document.getElementById('firstPage').addEventListener('click', () => actions.firstPage(api));
document.getElementById('prevPage').addEventListener('click', () => actions.prevPage(api));
document.getElementById('nextPage').addEventListener('click', () => actions.nextPage(api));
document.getElementById('lastPage').addEventListener('click', () => actions.lastPage(api));
example.js
const rows = Array.from({ length: 237 }, (_, i) => ({
  id: i + 1,
  name: `Item ${i + 1}`,
  qty: (i * 7) % 50,
}));
// summary sets the summary text, pageButtons the number of page buttons, and parts which parts show and in what order.
// With autoPageSize on, the rows per page follow the grid height (a numeric rowHeight is required).
const optionsFor = (layout) => ({
  columns: [
    { id: 'id', title: 'ID', kind: 'number', width: 70 },
    { id: 'name', title: 'Name', width: 160 },
    { id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end' },
  ],
  rows,
  rowKey: 'id',
  rowHeight: 32,
  pagination: layout === 'default'
    ? { mode: 'client', pageSize: 10, pageSizes: [10, 20, 50] }
    : layout === 'compact'
      ? {
        mode: 'client',
        pageSize: 10,
        pageButtons: 5,
        parts: ['nav', 'summary'],
        summary: (info) => `Page ${info.page}/${info.pageCount} · ${info.totalRows} rows`,
      }
      : { mode: 'client', pageSize: 10, autoPageSize: true, parts: ['summary', 'nav'] },
});
export const options = optionsFor('default');
export const actions = {
  layout: (api, value) => api.setOptions(optionsFor((value ?? 'default'))),
  firstPage: (api) => api.firstPage(),
  prevPage: (api) => api.prevPage(),
  nextPage: (api) => api.nextPage(),
  lastPage: (api) => api.lastPage(),
};