헤더 언어 바꾸기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.
코드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)
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<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>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));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'}`,
});
},
};<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>헤더 언어 바꾸기</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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')}`,
},
];
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 = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
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'}`,
});
},
};
options.ariaLabel = "헤더 언어 바꾸기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('language').addEventListener('change', (event) => actions.language(api, event.target.value));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="헤더 언어"
disabled={!api}
onChange={(event) => api && actions.language(api, event.target.value)}
>
<option value="ko">한국어 (기본)</option>
<option value="en">English</option>
</select>
</div>
<Grid style={{ height: 170 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
amount: number;
}
type Lang = 'ko' | 'en';
const TITLES: Record<Lang, Record<string, string>> = {
ko: { id: '번호', name: '이름', team: '팀', amount: '금액(원)' },
en: { id: 'No.', name: 'Name', team: 'Team', amount: 'Amount (KRW)' },
};
const columns = (lang: Lang): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
export const actions = {
language: (api: GridApi<Row>, value?: string) => {
const lang: Lang = value === 'en' ? 'en' : 'ko';
api.setColumns(columns(lang));
say({
ko: `헤더를 ${lang === 'ko' ? '한국어' : '영어'}로 바꿨어요`,
en: `Header switched to ${lang === 'ko' ? 'Korean' : 'English'}`,
});
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="헤더 언어"
:disabled="!api"
@change="api && actions.language(api, ($event.target as HTMLSelectElement).value)"
>
<option value="ko" selected>한국어 (기본)</option>
<option value="en">English</option>
</select>
</div>
<Grid style="height: 170px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
amount: number;
}
type Lang = 'ko' | 'en';
const TITLES: Record<Lang, Record<string, string>> = {
ko: { id: '번호', name: '이름', team: '팀', amount: '금액(원)' },
en: { id: 'No.', name: 'Name', team: 'Team', amount: 'Amount (KRW)' },
};
const columns = (lang: Lang): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
export const actions = {
language: (api: GridApi<Row>, value?: string) => {
const lang: Lang = value === 'en' ? 'en' : 'ko';
api.setColumns(columns(lang));
say({
ko: `헤더를 ${lang === 'ko' ? '한국어' : '영어'}로 바꿨어요`,
en: `Header switched to ${lang === 'ko' ? 'Korean' : 'English'}`,
});
},
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="헤더 언어"
[disabled]="!api"
(change)="api && actions.language(api, $any($event.target).value)"
>
<option value="ko" selected>한국어 (기본)</option>
<option value="en">English</option>
</select>
</div>
<mx-grid style="height: 170px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
amount: number;
}
type Lang = 'ko' | 'en';
const TITLES: Record<Lang, Record<string, string>> = {
ko: { id: '번호', name: '이름', team: '팀', amount: '금액(원)' },
en: { id: 'No.', name: 'Name', team: 'Team', amount: 'Amount (KRW)' },
};
const columns = (lang: Lang): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
export const actions = {
language: (api: GridApi<Row>, value?: string) => {
const lang: Lang = value === 'en' ? 'en' : 'ko';
api.setColumns(columns(lang));
say({
ko: `헤더를 ${lang === 'ko' ? '한국어' : '영어'}로 바꿨어요`,
en: `Header switched to ${lang === 'ko' ? 'Korean' : 'English'}`,
});
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<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>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));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'}`,
});
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Switch the header language</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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')}`,
},
];
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 = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
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'}`,
});
},
};
options.ariaLabel = "Switch the header language";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
document.getElementById('language').addEventListener('change', (event) => actions.language(api, event.target.value));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Header language"
disabled={!api}
onChange={(event) => api && actions.language(api, event.target.value)}
>
<option value="ko">Korean (default)</option>
<option value="en">English</option>
</select>
</div>
<Grid style={{ height: 170 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
amount: number;
}
type Lang = 'ko' | 'en';
const TITLES: Record<Lang, Record<string, string>> = {
ko: { id: '번호', name: '이름', team: '팀', amount: '금액(원)' },
en: { id: 'No.', name: 'Name', team: 'Team', amount: 'Amount (KRW)' },
};
const columns = (lang: Lang): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
export const actions = {
language: (api: GridApi<Row>, value?: string) => {
const lang: Lang = value === 'en' ? 'en' : 'ko';
api.setColumns(columns(lang));
say({
ko: `헤더를 ${lang === 'ko' ? '한국어' : '영어'}로 바꿨어요`,
en: `Header switched to ${lang === 'ko' ? 'Korean' : 'English'}`,
});
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Header language"
:disabled="!api"
@change="api && actions.language(api, ($event.target as HTMLSelectElement).value)"
>
<option value="ko" selected>Korean (default)</option>
<option value="en">English</option>
</select>
</div>
<Grid style="height: 170px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
amount: number;
}
type Lang = 'ko' | 'en';
const TITLES: Record<Lang, Record<string, string>> = {
ko: { id: '번호', name: '이름', team: '팀', amount: '금액(원)' },
en: { id: 'No.', name: 'Name', team: 'Team', amount: 'Amount (KRW)' },
};
const columns = (lang: Lang): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
export const actions = {
language: (api: GridApi<Row>, value?: string) => {
const lang: Lang = value === 'en' ? 'en' : 'ko';
api.setColumns(columns(lang));
say({
ko: `헤더를 ${lang === 'ko' ? '한국어' : '영어'}로 바꿨어요`,
en: `Header switched to ${lang === 'ko' ? 'Korean' : 'English'}`,
});
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Header language"
[disabled]="!api"
(change)="api && actions.language(api, $any($event.target).value)"
>
<option value="ko" selected>Korean (default)</option>
<option value="en">English</option>
</select>
</div>
<mx-grid style="height: 170px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
amount: number;
}
type Lang = 'ko' | 'en';
const TITLES: Record<Lang, Record<string, string>> = {
ko: { id: '번호', name: '이름', team: '팀', amount: '금액(원)' },
en: { id: 'No.', name: 'Name', team: 'Team', amount: 'Amount (KRW)' },
};
const columns = (lang: Lang): ColumnDef<Row>[] => [
{ 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: GridOptions<Row> = {
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: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
// 컬럼 id는 언어와 상관없이 그대로라서, 제목만 바꾼 정의로 setColumns를 불러도 사용자가 바꾼 폭·순서·고정은 그대로 남아요.
export const actions = {
language: (api: GridApi<Row>, value?: string) => {
const lang: Lang = value === 'en' ? 'en' : 'ko';
api.setColumns(columns(lang));
say({
ko: `헤더를 ${lang === 'ko' ? '한국어' : '영어'}로 바꿨어요`,
en: `Header switched to ${lang === 'ko' ? 'Korean' : 'English'}`,
});
},
};