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

헤더 언어 바꾸기Switch the header language

컬럼 번호표(id)는 그대로 두고 제목과 금액 표기만 다른 언어로 바꾸면, 사용자가 바꾼 폭·순서·고정은 그대로 남아요.Keep the column ids and swap the titles and the amount format to another language: the widths, order and pins the user set stay.

입문Beginner
직접 써 보기Live preview헤더 언어 바꾸기Switch the header 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="language">
      <option value="ko" selected>한국어 (기본)</option>
      <option value="en">English</option>
    </select>
  </div>
  <div id="grid" style="height: 170px"></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('language').addEventListener('change', (event) => actions.language(api, event.target.value));
example.js
const TITLES = {
  ko: { id: '번호', name: '이름', team: '팀', amount: '금액(원)' },
  en: { id: 'No.', name: 'Name', team: 'Team', amount: 'Amount (KRW)' },
};
const columns = (lang) => [
  { id: 'id', title: TITLES[lang].id, width: 80, align: 'end' },
  { id: 'name', title: TITLES[lang].name, width: 140 },
  { id: 'team', title: TITLES[lang].team, width: 130 },
  {
    id: 'amount',
    title: TITLES[lang].amount,
    kind: 'number',
    width: 140,
    align: 'end',
    formatValue: (value) => lang === 'ko'
      ? `${Number(value).toLocaleString('ko-KR')}원`
      : `KRW ${Number(value).toLocaleString('en-US')}`,
  },
];
export const options = {
  columns: columns('ko'),
  rows: [
    { id: 1, name: '김민준', team: '개발팀', amount: 4200000 },
    { id: 2, name: '이서연', team: '디자인팀', amount: 1850000 },
    { id: 3, name: '박지호', team: '영업팀', amount: 960000 },
  ],
  rowKey: 'id',
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  return () => { };
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
export const actions = {
  language: (api, value) => {
    const lang = value === 'en' ? 'en' : 'ko';
    api.setColumns(columns(lang));
    say({
      ko: `헤더를 ${lang === 'ko' ? '한국어' : '영어'}로 바꿨어요`,
      en: `Header switched to ${lang === 'ko' ? 'Korean' : 'English'}`,
    });
  },
};

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="Header language" id="language">
      <option value="ko" selected>Korean (default)</option>
      <option value="en">English</option>
    </select>
  </div>
  <div id="grid" style="height: 170px"></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('language').addEventListener('change', (event) => actions.language(api, event.target.value));
example.js
const TITLES = {
  ko: { id: '번호', name: '이름', team: '팀', amount: '금액(원)' },
  en: { id: 'No.', name: 'Name', team: 'Team', amount: 'Amount (KRW)' },
};
const columns = (lang) => [
  { id: 'id', title: TITLES[lang].id, width: 80, align: 'end' },
  { id: 'name', title: TITLES[lang].name, width: 140 },
  { id: 'team', title: TITLES[lang].team, width: 130 },
  {
    id: 'amount',
    title: TITLES[lang].amount,
    kind: 'number',
    width: 140,
    align: 'end',
    formatValue: (value) => lang === 'ko'
      ? `${Number(value).toLocaleString('ko-KR')}원`
      : `KRW ${Number(value).toLocaleString('en-US')}`,
  },
];
export const options = {
  columns: columns('ko'),
  rows: [
    { id: 1, name: '김민준', team: '개발팀', amount: 4200000 },
    { id: 2, name: '이서연', team: '디자인팀', amount: 1850000 },
    { id: 3, name: '박지호', team: '영업팀', amount: 960000 },
  ],
  rowKey: 'id',
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  return () => { };
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
export const actions = {
  language: (api, value) => {
    const lang = value === 'en' ? 'en' : 'ko';
    api.setColumns(columns(lang));
    say({
      ko: `헤더를 ${lang === 'ko' ? '한국어' : '영어'}로 바꿨어요`,
      en: `Header switched to ${lang === 'ko' ? 'Korean' : 'English'}`,
    });
  },
};