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

문자열 정렬 규칙(콜레이터) 바꾸기Change the string ordering rules (collator)

옵션 sortCollator로 대소문자 순서(caseFirst), 구분 정도(sensitivity), 숫자 자연순(numeric)을 정해요. 옵션을 바꾸면 같은 정렬 모델로 다시 정렬하고, api.getSortCollator()가 지금 콜레이터를 돌려줘요.The sortCollator option sets case order (caseFirst), sensitivity and numeric natural order. Changing it re-sorts with the same sort model, and api.getSortCollator() returns the collator in use.

활용Intermediate
직접 써 보기Live preview문자열 정렬 규칙(콜레이터) 바꾸기Change the string ordering rules (collator)

코드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="upper">대문자 먼저</button>
    <button type="button" id="lower">소문자 먼저</button>
    <button type="button" id="base">대소문자 무시</button>
    <button type="button" id="plain">숫자 자연순 끄기</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, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('upper').addEventListener('click', () => actions.upper(api));
document.getElementById('lower').addEventListener('click', () => actions.lower(api));
document.getElementById('base').addEventListener('click', () => actions.base(api));
document.getElementById('plain').addEventListener('click', () => actions.plain(api));
example.js
const rows = ['banana', 'Banana', 'apple', 'Apple', 'item10', 'item2', 'Äpfel', 'zebra'].map((word, i) => ({ id: i + 1, word }));
// sortCollator는 문자열 정렬 규칙이에요(Intl.Collator 옵션). 기본은 숫자 자연순(item2 < item10)이고
// caseFirst로 대소문자 순서를, sensitivity로 대소문자·악센트 구분 여부를 바꿔요.
export const options = {
  columns: [
    { id: 'id', title: '번호', kind: 'number', width: 70 },
    { id: 'word', title: '단어', width: 160 },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  api.setSortModel([{ columnId: 'word', direction: 'asc' }]);
  const off = api.on('optionsChanged', (e) => {
    if (e.changed.includes('sortCollator')) {
      const c = api.getSortCollator().resolvedOptions();
      log({
        ko: `콜레이터: caseFirst ${c.caseFirst}, sensitivity ${c.sensitivity}, numeric ${String(c.numeric)}`,
        en: `Collator: caseFirst ${c.caseFirst}, sensitivity ${c.sensitivity}, numeric ${String(c.numeric)}`,
      });
    }
  });
  return () => off();
}
export const actions = {
  upper: (api) => api.setOptions({ sortCollator: { caseFirst: 'upper' } }),
  lower: (api) => api.setOptions({ sortCollator: { caseFirst: 'lower' } }),
  base: (api) => api.setOptions({ sortCollator: { sensitivity: 'base' } }),
  plain: (api) => api.setOptions({ sortCollator: { numeric: false } }),
};

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="upper">Upper case first</button>
    <button type="button" id="lower">Lower case first</button>
    <button type="button" id="base">Ignore case</button>
    <button type="button" id="plain">Natural numbers off</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, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('upper').addEventListener('click', () => actions.upper(api));
document.getElementById('lower').addEventListener('click', () => actions.lower(api));
document.getElementById('base').addEventListener('click', () => actions.base(api));
document.getElementById('plain').addEventListener('click', () => actions.plain(api));
example.js
const rows = ['banana', 'Banana', 'apple', 'Apple', 'item10', 'item2', 'Äpfel', 'zebra'].map((word, i) => ({ id: i + 1, word }));
// sortCollator is the string ordering rule (Intl.Collator options). The default is natural number order (item2 < item10);
// caseFirst changes the case order, and sensitivity changes whether case and accents are told apart.
export const options = {
  columns: [
    { id: 'id', title: 'No.', kind: 'number', width: 70 },
    { id: 'word', title: 'Word', width: 160 },
  ],
  rows,
  rowKey: 'id',
};
export function setup(api, log) {
  api.setSortModel([{ columnId: 'word', direction: 'asc' }]);
  const off = api.on('optionsChanged', (e) => {
    if (e.changed.includes('sortCollator')) {
      const c = api.getSortCollator().resolvedOptions();
      log(`Collator: caseFirst ${c.caseFirst}, sensitivity ${c.sensitivity}, numeric ${String(c.numeric)}`);
    }
  });
  return () => off();
}
export const actions = {
  upper: (api) => api.setOptions({ sortCollator: { caseFirst: 'upper' } }),
  lower: (api) => api.setOptions({ sortCollator: { caseFirst: 'lower' } }),
  base: (api) => api.setOptions({ sortCollator: { sensitivity: 'base' } }),
  plain: (api) => api.setOptions({ sortCollator: { numeric: false } }),
};