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

한 페이지 개수와 안내 문구 바꾸기Change rows per page and the pager text

한 페이지에 15건씩 보이게 하고, 페이지 막대의 위치(위·아래)와 "총 300건 중 1–15" 같은 안내 문구를 내 말투로 바꿔요. 설정 몇 줄이면 돼요.Show 15 rows per page, move the pager to the top or bottom, and replace the "1–15 of 300" text with your own wording. A few settings are enough.

입문Beginner
직접 써 보기Live preview한 페이지 개수와 안내 문구 바꾸기Change rows per page and the pager text

코드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="position">
      <option value="bottom" selected>아래 (기본)</option>
      <option value="top">위</option>
    </select>
    <select aria-label="안내 문구" id="messages">
      <option value="default" selected>기본 문구</option>
      <option value="custom">내 문구</option>
    </select>
  </div>
  <div id="grid" style="height: 600px"></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);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('messages').addEventListener('change', (event) => actions.messages(api, event.target.value));
example.js
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const authors = ['김민준', '이서연', '박지호', '최유나', '정도윤'];
// 게시판 글 300건을 한 페이지 15건으로 보여 줘요.
// pagination.messages로 페이지 막대 아래 안내 문구를 바꾸고, position으로 막대를 위·아래에 둘 수 있어요.
const MESSAGES = {
  default: {},
  custom: {
    summary: L('게시글 {total}개 중 {from}번~{to}번 보는 중', 'Showing posts {from}-{to} of {total}'),
  },
};
const build = (position, messages) => ({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] });
export const options = {
  columns: [
    { id: 'title', title: '제목', width: 260 },
    { id: 'author', title: '작성자', width: 110 },
    {
      id: 'views',
      title: '조회수',
      kind: 'number',
      width: 110,
      align: 'end',
      formatValue: (value) => Number(value).toLocaleString('ko-KR'),
    },
  ],
  rows: Array.from({ length: 300 }, (_, i) => ({
    id: i + 1,
    title: `공지사항 ${300 - i}번째 안내드립니다`,
    author: authors[i % 5],
    views: 120 + ((i * 7919) % 9000),
  })),
  rowKey: 'id',
  pagination: build('bottom', 'default'),
};
let position = 'bottom';
let messages = 'default';
const apply = (api) => api.setOptions({ pagination: build(position, messages) });
export function setup() {
  position = 'bottom';
  messages = 'default';
  return () => { };
}
export const actions = {
  position: (api, value) => {
    position = value === 'top' ? 'top' : 'bottom';
    apply(api);
  },
  messages: (api, value) => {
    messages = value === 'custom' ? 'custom' : 'default';
    apply(api);
  },
};

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 position" id="position">
      <option value="bottom" selected>Bottom (default)</option>
      <option value="top">Top</option>
    </select>
    <select aria-label="Pager text" id="messages">
      <option value="default" selected>Default</option>
      <option value="custom">Custom</option>
    </select>
  </div>
  <div id="grid" style="height: 600px"></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);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));
document.getElementById('messages').addEventListener('change', (event) => actions.messages(api, event.target.value));
example.js
const authors = ['Liam Carter', 'Emma Stone', 'Noah Kim', 'Olivia Park', 'Ethan Brown'];
// Show 300 board posts, 15 per page.
// pagination.messages changes the text under the pager, and position puts the bar on top or at the bottom.
const MESSAGES = {
  default: {},
  custom: {
    summary: 'Showing posts {from}-{to} of {total}',
  },
};
const build = (position, messages) => ({ mode: 'client', pageSize: 15, position, messages: MESSAGES[messages] });
export const options = {
  columns: [
    { id: 'title', title: 'Title', width: 260 },
    { id: 'author', title: 'Author', width: 120 },
    {
      id: 'views',
      title: 'Views',
      kind: 'number',
      width: 110,
      align: 'end',
      formatValue: (value) => Number(value).toLocaleString('en-US'),
    },
  ],
  rows: Array.from({ length: 300 }, (_, i) => ({
    id: i + 1,
    title: `Announcement no. ${300 - i}`,
    author: authors[i % 5],
    views: 120 + ((i * 7919) % 9000),
  })),
  rowKey: 'id',
  pagination: build('bottom', 'default'),
};
let position = 'bottom';
let messages = 'default';
const apply = (api) => api.setOptions({ pagination: build(position, messages) });
export function setup() {
  position = 'bottom';
  messages = 'default';
  return () => { };
}
export const actions = {
  position: (api, value) => {
    position = value === 'top' ? 'top' : 'bottom';
    apply(api);
  },
  messages: (api, value) => {
    messages = value === 'custom' ? 'custom' : 'default';
    apply(api);
  },
};