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

페이지 막대 모양 고르기Choose the pager style

pager 옵션으로 페이지 막대를 기본(처음·번호·끝), 간단(이전·다음과 n / m), 버튼(번호 버튼만) 중에서 골라요.The pager option switches the page bar between full (first, numbers, last), simple (previous, next and "n of m") and button (numbered buttons only).

입문Beginner
직접 써 보기Live preview페이지 막대 모양 고르기Choose the pager style

코드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="pager">
      <option value="full" selected>기본</option>
      <option value="simple">간단</option>
      <option value="button">버튼</option>
    </select>
  </div>
  <div id="grid" style="height: 330px"></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('pager').addEventListener('change', (event) => actions.pager(api, event.target.value));
example.js
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희', '오세훈', '윤지아'];
const teams = ['개발팀', '디자인팀', '영업팀', '인사팀'];
const paging = (pager) => ({
  mode: 'client',
  pageSize: 5,
  pageSizes: [5, 10],
  // 막대를 표 위에 두어서, 모양을 고르는 선택 칸과 바뀐 막대가 한 화면에 같이 보여요.
  position: 'top',
  // pager: 'full'(기본) | 'simple'(이전·다음과 n / m) | 'button'(번호 버튼)
  pager,
  // 간단 모양의 "n / m" 문구도 다른 곳처럼 '페이지'로 맞춰요.
  messages: { pageOf: '{page} / {total} 페이지' },
});
export const options = {
  columns: [
    { id: 'employee', title: '이름', width: 140 },
    { id: 'team', title: '팀', width: 120 },
  ],
  rows: Array.from({ length: 120 }, (_, i) => ({
    id: i + 1,
    employee: `${names[i % 8]} ${i + 1}`,
    team: teams[(i * 3) % 4],
  })),
  rowKey: 'id',
  pagination: paging('full'),
};
export function setup(api, log) {
  const off = api.on('pageChanged', ({ page, pageCount }) => log({ ko: `${page} / ${pageCount} 페이지`, en: `Page ${page} / ${pageCount}` }));
  return () => off();
}
export const actions = {
  // 모양만 바뀌고 현재 페이지와 페이지당 행 수는 그대로예요.
  pager: (api, value) => api.setOptions({ pagination: paging((value ?? 'full')) }),
};

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 style" id="pager">
      <option value="full" selected>Full (default)</option>
      <option value="simple">Simple</option>
      <option value="button">Buttons</option>
    </select>
  </div>
  <div id="grid" style="height: 330px"></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('pager').addEventListener('change', (event) => actions.pager(api, event.target.value));
example.js
const names = [
  'Liam Carter',
  'Emma Stone',
  'Noah Kim',
  'Olivia Park',
  'Ethan Brown',
  'Mia Johnson',
  'Jack Miller',
  'Zoe Davis',
];
const teams = ['Dev', 'Design', 'Sales', 'HR'];
const paging = (pager) => ({
  mode: 'client',
  pageSize: 5,
  pageSizes: [5, 10],
  // Put the bar above the table so the select that picks the style and the changed bar are on screen together.
  position: 'top',
  // pager: 'full' (default) | 'simple' (previous/next and n / m) | 'button' (number buttons)
  pager,
  // Make the "n / m" text of the simple style say "Page" like the other places.
  messages: { pageOf: 'Page {page} / {total}' },
});
export const options = {
  columns: [
    { id: 'employee', title: 'Name', width: 170 },
    { id: 'team', title: 'Team', width: 120 },
  ],
  rows: Array.from({ length: 120 }, (_, i) => ({
    id: i + 1,
    employee: `${names[i % 8]} ${i + 1}`,
    team: teams[(i * 3) % 4],
  })),
  rowKey: 'id',
  pagination: paging('full'),
};
export function setup(api, log) {
  const off = api.on('pageChanged', ({ page, pageCount }) => log(`Page ${page} / ${pageCount}`));
  return () => off();
}
export const actions = {
  // Only the style changes; the current page and the rows per page stay the same.
  pager: (api, value) => api.setOptions({ pagination: paging((value ?? 'full')) }),
};