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

500건을 20건씩 나눠 보기Split 500 rows into pages of 20

주문 500건을 한 번에 넣고 페이지 나누기만 켜면 20건씩 나눠 보여요. 아래 페이지 막대에서 이동하거나 페이지 번호를 직접 입력할 수 있고, 행 번호는 페이지를 넘어서도 이어져요.Load 500 orders at once, switch paging on and they show 20 at a time. Move with the pager or type a page number; row numbers continue across pages.

입문Beginner
직접 써 보기Live preview500건을 20건씩 나눠 보기Split 500 rows into pages of 20

코드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="first">첫 페이지</button>
    <button type="button" id="page5">5페이지로</button>
    <button type="button" id="last">마지막 페이지</button>
    <button type="button" id="row200">200번째 행 찾아가기</button>
  </div>
  <div id="grid" style="height: 760px"></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('first').addEventListener('click', () => actions.first(api));
document.getElementById('page5').addEventListener('click', () => actions.page5(api));
document.getElementById('last').addEventListener('click', () => actions.last(api));
document.getElementById('row200').addEventListener('click', () => actions.row200(api));
example.js
const customers = [
  '한빛물류',
  '푸른하늘식품',
  '북극성무역',
  '다온상사',
  '새벽농원',
  '모아패션',
  '해든전자',
];
const regions = ['서울', '부산', '대구', '인천', '광주', '대전', '제주'];
const products = ['무선 이어폰', '스마트 워치', '노트북 거치대', '보조배터리', '블루투스 스피커'];
// 주문 500건을 한꺼번에 넣고 pagination만 켜면, 그리드가 알아서 20건씩 나눠 보여 줘요.
// 행 번호(showRowNumbers)는 페이지가 바뀌어도 이어서 매겨져요.
export const options = {
  columns: [
    { id: 'customer', title: '고객사', width: 130 },
    { id: 'region', title: '지역', width: 90 },
    { id: 'product', title: '상품', width: 160 },
    { id: 'quantity', title: '수량', kind: 'number', width: 90, align: 'end' },
    {
      id: 'amount',
      title: '금액(원)',
      kind: 'number',
      width: 130,
      align: 'end',
      formatValue: (value) => Number(value).toLocaleString('ko-KR'),
    },
  ],
  rows: Array.from({ length: 500 }, (_, i) => ({
    id: i + 1,
    customer: customers[i % 7],
    region: regions[(i * 3) % 7],
    product: products[(i * 7) % 5],
    quantity: 1 + ((i * 13) % 30),
    amount: 30000 + i * 900, // 행 번호가 커질수록 금액이 조금씩 늘어나서, 페이지를 넘겨도 값이 차분해요
  })),
  rowKey: 'id',
  showRowNumbers: true,
  // jump: true면 페이지 번호를 직접 입력해서 이동하는 칸이 생겨요.
  pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api, log) {
  const off = api.on('pageChanged', ({ page, pageCount }) => {
    const info = api.getPageInfo();
    log({
      ko: `${page} / ${pageCount} 페이지 · ${info.from}~${info.to}번째 행`,
      en: `Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`,
    });
  });
  return () => off();
}
export const actions = {
  page5: (api) => api.setPage(5),
  last: (api) => api.setPage(api.getPageCount()),
  // 200번째 행을 찾아가요: 그 행이 있는 페이지로 이동하고 금액 칸에 포커스를 둬요.
  row200: (api) => {
    api.setPage(Math.ceil(200 / api.getPageSize()));
    api.focusCell(200, 'amount');
  },
  first: (api) => api.setPage(1),
};

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="first">First page</button>
    <button type="button" id="page5">Go to page 5</button>
    <button type="button" id="last">Last page</button>
    <button type="button" id="row200">Show row 200</button>
  </div>
  <div id="grid" style="height: 760px"></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('first').addEventListener('click', () => actions.first(api));
document.getElementById('page5').addEventListener('click', () => actions.page5(api));
document.getElementById('last').addEventListener('click', () => actions.last(api));
document.getElementById('row200').addEventListener('click', () => actions.row200(api));
example.js
const customers = [
  'Harbor Logistics',
  'Blue Sky Foods',
  'Polaris Trading',
  'Dawn Commerce',
  'Sunrise Farm',
  'Moda Fashion',
  'Bright Electronics',
];
const regions = ['New York', 'Boston', 'Austin', 'Seattle', 'Chicago', 'Denver', 'Miami'];
const products = [
  'Wireless earbuds',
  'Smart watch',
  'Laptop stand',
  'Power bank',
  'Bluetooth speaker',
];
// Load 500 orders at once and just turn on pagination, and the grid splits them into pages of 20 by itself.
// Row numbers (showRowNumbers) keep counting across pages.
export const options = {
  columns: [
    { id: 'customer', title: 'Customer', width: 150 },
    { id: 'region', title: 'Region', width: 100 },
    { id: 'product', title: 'Product', width: 170 },
    { id: 'quantity', title: 'Qty', kind: 'number', width: 90, align: 'end' },
    {
      id: 'amount',
      title: 'Amount ($)',
      kind: 'number',
      width: 130,
      align: 'end',
      formatValue: (value) => Number(value).toLocaleString('en-US'),
    },
  ],
  rows: Array.from({ length: 500 }, (_, i) => ({
    id: i + 1,
    customer: customers[i % 7],
    region: regions[(i * 3) % 7],
    product: products[(i * 7) % 5],
    quantity: 1 + ((i * 13) % 30),
    amount: 30 + Math.round(i * 0.9), // the amount grows slowly with the row number, so the values stay calm as you page
  })),
  rowKey: 'id',
  showRowNumbers: true,
  // jump: true adds a box where you can type a page number to go to it.
  pagination: { mode: 'client', pageSize: 20, jump: true },
};
export function setup(api, log) {
  const off = api.on('pageChanged', ({ page, pageCount }) => {
    const info = api.getPageInfo();
    log(`Page ${page} / ${pageCount} · rows ${info.from}-${info.to}`);
  });
  return () => off();
}
export const actions = {
  page5: (api) => api.setPage(5),
  last: (api) => api.setPage(api.getPageCount()),
  // Go find row 200: move to the page that holds it and focus its Amount cell.
  row200: (api) => {
    api.setPage(Math.ceil(200 / api.getPageSize()));
    api.focusCell(200, 'amount');
  },
  first: (api) => api.setPage(1),
};