가나다순과 숫자 순서가 자연스럽게Natural sorting for Korean text and numbers
글자 컬럼은 한글 사전 순서로, '보고서 2'가 '보고서 10'보다 앞에 오는 자연스러운 숫자 순서로 정렬돼요. 같은 값끼리는 원래 순서를 지키고, 악센트 있는 글자는 정렬용 값을 따로 계산해 일반 글자처럼 정렬할 수 있어요.Text columns sort in Korean dictionary order and natural number order, so Report 2 comes before Report 10. Equal values keep their original order, and accented text can sort like plain letters with a computed sort value.
코드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">
<button type="button" id="fileAsc">파일 오름차순</button>
<button type="button" id="ownerAsc">담당 가나다순</button>
<button type="button" id="ownerDesc">담당 역순</button>
<button type="button" id="cityAsc">도시 오름차순</button>
<button type="button" id="clear">정렬 해제</button>
</div>
<div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('fileAsc').addEventListener('click', () => actions.fileAsc(api));
document.getElementById('ownerAsc').addEventListener('click', () => actions.ownerAsc(api));
document.getElementById('ownerDesc').addEventListener('click', () => actions.ownerDesc(api));
document.getElementById('cityAsc').addEventListener('click', () => actions.cityAsc(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text) => text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
export const options = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
export const actions = {
fileAsc: (api) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api) => api.setSortModel([]),
};<!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">
<button type="button" id="fileAsc">파일 오름차순</button>
<button type="button" id="ownerAsc">담당 가나다순</button>
<button type="button" id="ownerDesc">담당 역순</button>
<button type="button" id="cityAsc">도시 오름차순</button>
<button type="button" id="clear">정렬 해제</button>
</div>
<div id="grid" style="height: 330px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text) => text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
const options = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
const actions = {
fileAsc: (api) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api) => api.setSortModel([]),
};
options.ariaLabel = "가나다순과 숫자 순서가 자연스럽게";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('fileAsc').addEventListener('click', () => actions.fileAsc(api));
document.getElementById('ownerAsc').addEventListener('click', () => actions.ownerAsc(api));
document.getElementById('ownerDesc').addEventListener('click', () => actions.ownerDesc(api));
document.getElementById('cityAsc').addEventListener('click', () => actions.cityAsc(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
</script>
</body>
</html>버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.fileAsc(api)}
>파일 오름차순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ownerAsc(api)}
>담당 가나다순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ownerDesc(api)}
>담당 역순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.cityAsc(api)}
>도시 오름차순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>정렬 해제</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
file: string;
owner: string;
city: string;
pages: number;
}
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text: string): string =>
text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
export const options: GridOptions<Row> = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
export const actions = {
fileAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api: GridApi<Row>) => api.setSortModel([]),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.fileAsc(api)">파일 오름차순</button>
<button
type="button"
:disabled="!api"
@click="api && actions.ownerAsc(api)"
>담당 가나다순</button>
<button
type="button"
:disabled="!api"
@click="api && actions.ownerDesc(api)"
>담당 역순</button>
<button type="button" :disabled="!api" @click="api && actions.cityAsc(api)">도시 오름차순</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">정렬 해제</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
file: string;
owner: string;
city: string;
pages: number;
}
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text: string): string =>
text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
export const options: GridOptions<Row> = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
export const actions = {
fileAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api: GridApi<Row>) => api.setSortModel([]),
};버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.fileAsc(api)"
>파일 오름차순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ownerAsc(api)"
>담당 가나다순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ownerDesc(api)"
>담당 역순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.cityAsc(api)"
>도시 오름차순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>정렬 해제</button>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
file: string;
owner: string;
city: string;
pages: number;
}
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text: string): string =>
text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
export const options: GridOptions<Row> = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
export const actions = {
fileAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api: GridApi<Row>) => api.setSortModel([]),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<button type="button" id="fileAsc">File ascending</button>
<button type="button" id="ownerAsc">Owner A→Z</button>
<button type="button" id="ownerDesc">Owner Z→A</button>
<button type="button" id="cityAsc">City ascending</button>
<button type="button" id="clear">Clear sort</button>
</div>
<div id="grid" style="height: 330px"></div>
</div>
<script type="module" src="./main.js"></script>import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('fileAsc').addEventListener('click', () => actions.fileAsc(api));
document.getElementById('ownerAsc').addEventListener('click', () => actions.ownerAsc(api));
document.getElementById('ownerDesc').addEventListener('click', () => actions.ownerDesc(api));
document.getElementById('cityAsc').addEventListener('click', () => actions.cityAsc(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text) => text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
export const options = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
export const actions = {
fileAsc: (api) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api) => api.setSortModel([]),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Natural sorting for Korean text and numbers</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="fileAsc">File ascending</button>
<button type="button" id="ownerAsc">Owner A→Z</button>
<button type="button" id="ownerDesc">Owner Z→A</button>
<button type="button" id="cityAsc">City ascending</button>
<button type="button" id="clear">Clear sort</button>
</div>
<div id="grid" style="height: 330px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text) => text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
const options = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
const actions = {
fileAsc: (api) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api) => api.setSortModel([]),
};
options.ariaLabel = "Natural sorting for Korean text and numbers";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('fileAsc').addEventListener('click', () => actions.fileAsc(api));
document.getElementById('ownerAsc').addEventListener('click', () => actions.ownerAsc(api));
document.getElementById('ownerDesc').addEventListener('click', () => actions.ownerDesc(api));
document.getElementById('cityAsc').addEventListener('click', () => actions.cityAsc(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
</script>
</body>
</html>When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
return (
<>
<div className="toolbar">
<button
type="button"
disabled={!api}
onClick={() => api && actions.fileAsc(api)}
>File ascending</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ownerAsc(api)}
>Owner A→Z</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.ownerDesc(api)}
>Owner Z→A</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.cityAsc(api)}
>City ascending</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear sort</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
file: string;
owner: string;
city: string;
pages: number;
}
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text: string): string =>
text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
export const options: GridOptions<Row> = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
export const actions = {
fileAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api: GridApi<Row>) => api.setSortModel([]),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
}
</script>
<template>
<div class="toolbar">
<button type="button" :disabled="!api" @click="api && actions.fileAsc(api)">File ascending</button>
<button
type="button"
:disabled="!api"
@click="api && actions.ownerAsc(api)"
>Owner A→Z</button>
<button
type="button"
:disabled="!api"
@click="api && actions.ownerDesc(api)"
>Owner Z→A</button>
<button type="button" :disabled="!api" @click="api && actions.cityAsc(api)">City ascending</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear sort</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
file: string;
owner: string;
city: string;
pages: number;
}
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text: string): string =>
text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
export const options: GridOptions<Row> = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
export const actions = {
fileAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api: GridApi<Row>) => api.setSortModel([]),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<button
type="button"
[disabled]="!api"
(click)="api && actions.fileAsc(api)"
>File ascending</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ownerAsc(api)"
>Owner A→Z</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.ownerDesc(api)"
>Owner Z→A</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.cityAsc(api)"
>City ascending</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear sort</button>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
}
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export interface Row {
id: number;
file: string;
owner: string;
city: string;
pages: number;
}
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 2"가 "보고서 10"보다 앞에 오고, 한글은 가나다 순서예요. 비교 함수는 필요 없어요.
// 악센트가 있는 글자(Élodie)를 일반 글자처럼 정렬하고 싶으면 정렬용 값을 따로 계산해 둔 컬럼을 써요.
const fold = (text: string): string =>
text.normalize('NFD').replace(/\p{M}/gu, '').toLocaleLowerCase();
export const options: GridOptions<Row> = {
columns: [
{ id: 'file', title: '파일', width: 160 },
{ id: 'owner', title: '담당', width: 120 },
// 보이는 글자는 그대로, 정렬은 악센트·대소문자를 무시한 값으로 해요.
{
id: 'city',
title: '도시 (악센트 무시)',
width: 170,
getValue: (row) => fold(row.city),
formatValue: (_value, row) => row.city,
},
{ id: 'pages', title: '쪽수', kind: 'number', width: 90, align: 'end' },
],
rows: [
{ id: 1, file: '보고서 10', owner: '최하은', city: 'Zürich', pages: 12 },
{ id: 2, file: '보고서 2', owner: '김서연', city: 'émile-ville', pages: 8 },
{ id: 3, file: '보고서 1', owner: '이도윤', city: 'Amsterdam', pages: 30 },
{ id: 4, file: '보고서 21', owner: '박지후', city: 'élan', pages: 5 },
{ id: 5, file: '보고서 3', owner: '강민서', city: 'Berlin', pages: 17 },
{ id: 6, file: '보고서 100', owner: '정우진', city: 'cádiz', pages: 44 },
{ id: 7, file: '보고서 11', owner: '윤지안', city: 'Çanakkale', pages: 9 },
{ id: 8, file: '보고서 9', owner: '가은', city: 'Dublin', pages: 21 },
],
rowKey: 'id',
};
export const actions = {
fileAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'file', direction: 'asc' }]),
ownerAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'asc' }]),
ownerDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'owner', direction: 'desc' }]),
cityAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'city', direction: 'asc' }]),
clear: (api: GridApi<Row>) => api.setSortModel([]),
};