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

언어팩을 등록하고 화면 언어 바꾸기Register a language pack and switch the grid language

작은 일본어 팩을 그리드에 주고, 한국어·영어·일본어로 바꿔 봐요. 페이저, 필터 줄, 컬럼 메뉴, 합계 줄의 문구가 따라가요.Give the grid a small Japanese pack and switch between Korean, English and Japanese. The pager, filter row, column menu and total row follow.

활용Intermediate
직접 써 보기Live preview언어팩을 등록하고 화면 언어 바꾸기Register a language pack and switch the grid language

코드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="locale">
      <option value="ja" selected>일본어(작은 팩)</option>
      <option value="en">영어(내장)</option>
      <option value="ko">한국어(내장)</option>
    </select>
  </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('locale').addEventListener('change', (event) => actions.locale(api, event.target.value));
example.js
// 표 데이터는 어느 언어로 보아도 같게 코드와 숫자로만 만들었어요. 바뀌는 것은 그리드가 스스로 쓰는 문구예요.
const rows = Array.from({ length: 12 }, (_, i) => ({
  id: i + 1,
  sku: `A-${101 + i}`,
  qty: 3 + ((i * 7) % 20),
  price: 1200 + i * 350,
}));
const ja = {
  code: 'ja',
  messages: {
    noRows: '表示する行がありません。',
    loading: '読み込み中…',
    columnMenuLabel: '列メニュー',
    menuSortAsc: '昇順で並べ替え',
    menuSortDesc: '降順で並べ替え',
    menuHide: '列を非表示',
  },
  pager: {
    nav: 'ページ送り',
    first: '最初のページ',
    previous: '前のページ',
    next: '次のページ',
    last: '最後のページ',
    pageNumber: '{page}ページ',
    pageSize: '1ページの行数',
    summary: '全{total}件中 {from}–{to}件',
    empty: '表示する行がありません',
  },
  filter: {
    rowLabel: 'フィルター',
    inputLabel: '{title}で絞り込み',
    clearAll: 'すべてのフィルターを解除',
    clearOne: '{title}のフィルターを解除',
    all: 'すべて',
  },
  text: { summaryTotal: '合計', selectAll: 'すべて選択' },
};
// 그리드의 접근성 이름(ariaLabel)도 고른 언어로 바꿔요.
const LABELS = {
  ja: 'ロケールパックのデモ',
  en: 'Locale pack demo',
  ko: '언어팩 데모',
};
export const options = {
  ariaLabel: LABELS.ja,
  columns: [
    { id: 'sku', title: 'SKU', width: 100 },
    { id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
    { id: 'price', title: 'Price', kind: 'number', width: 100, align: 'end', aggregate: 'sum' },
  ],
  rows,
  rowKey: 'id',
  selection: { mode: 'multiple', checkbox: true },
  pagination: { mode: 'client', pageSize: 5 },
  filterRow: true,
  columnMenu: true,
  summary: true,
  // 이 그리드에만 팩을 준다(전역 없음). npm 패키지에서는 registerLocale(pack)로 한 번 등록해 두면 모든 그리드가 쓴다.
  locale: 'ja',
  localePacks: [ja],
};
export const actions = {
  // locale만 바꾸면 페이저, 필터 줄, 컬럼 메뉴, 합계 줄의 문구가 다음 화면 갱신에 새 언어로 나와요.
  locale: (api, value = 'ja') => api.setOptions({ locale: value, ariaLabel: LABELS[value] ?? LABELS.en }),
};

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="Language" id="locale">
      <option value="ja" selected>Japanese (small pack)</option>
      <option value="en">English (built in)</option>
      <option value="ko">Korean (built in)</option>
    </select>
  </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('locale').addEventListener('change', (event) => actions.locale(api, event.target.value));
example.js
// The table data is only codes and numbers, so it looks the same in any language. What changes is the text the grid itself uses.
const rows = Array.from({ length: 12 }, (_, i) => ({
  id: i + 1,
  sku: `A-${101 + i}`,
  qty: 3 + ((i * 7) % 20),
  price: 1200 + i * 350,
}));
const ja = {
  code: 'ja',
  messages: {
    noRows: '表示する行がありません。',
    loading: '読み込み中…',
    columnMenuLabel: '列メニュー',
    menuSortAsc: '昇順で並べ替え',
    menuSortDesc: '降順で並べ替え',
    menuHide: '列を非表示',
  },
  pager: {
    nav: 'ページ送り',
    first: '最初のページ',
    previous: '前のページ',
    next: '次のページ',
    last: '最後のページ',
    pageNumber: '{page}ページ',
    pageSize: '1ページの行数',
    summary: '全{total}件中 {from}–{to}件',
    empty: '表示する行がありません',
  },
  filter: {
    rowLabel: 'フィルター',
    inputLabel: '{title}で絞り込み',
    clearAll: 'すべてのフィルターを解除',
    clearOne: '{title}のフィルターを解除',
    all: 'すべて',
  },
  text: { summaryTotal: '合計', selectAll: 'すべて選択' },
};
// The grid's accessible name (ariaLabel) also changes to the chosen language.
const LABELS = {
  ja: 'ロケールパックのデモ',
  en: 'Locale pack demo',
  ko: 'Locale pack demo',
};
export const options = {
  ariaLabel: LABELS.ja,
  columns: [
    { id: 'sku', title: 'SKU', width: 100 },
    { id: 'qty', title: 'Qty', kind: 'number', width: 90, align: 'end', aggregate: 'sum' },
    { id: 'price', title: 'Price', kind: 'number', width: 100, align: 'end', aggregate: 'sum' },
  ],
  rows,
  rowKey: 'id',
  selection: { mode: 'multiple', checkbox: true },
  pagination: { mode: 'client', pageSize: 5 },
  filterRow: true,
  columnMenu: true,
  summary: true,
  // Give the pack to this grid only (no globals). With the npm package, register it once with registerLocale(pack) and every grid uses it.
  locale: 'ja',
  localePacks: [ja],
};
export const actions = {
  // Changing only locale makes the pager, filter row, column menu and summary row text appear in the new language on the next screen update.
  locale: (api, value = 'ja') => api.setOptions({ locale: value, ariaLabel: LABELS[value] ?? LABELS.en }),
};