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

가나다순과 숫자 순서가 자연스럽게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.

입문Beginner
직접 써 보기Live preview가나다순과 숫자 순서가 자연스럽게Natural sorting for Korean text and numbers

코드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">
    <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>
main.js
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));
example.js
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 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([]),
};

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">
    <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>
main.js
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));
example.js
// 글자 컬럼은 한국어 사전 순서로, 숫자가 섞여 있으면 자연스러운 숫자 순서로 정렬해요.
// "보고서 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([]),
};