문자열 정렬 규칙(콜레이터) 바꾸기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.
코드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="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>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));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 } }),
};<!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="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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const rows = ['banana', 'Banana', 'apple', 'Apple', 'item10', 'item2', 'Äpfel', 'zebra'].map((word, i) => ({ id: i + 1, word }));
// sortCollator는 문자열 정렬 규칙이에요(Intl.Collator 옵션). 기본은 숫자 자연순(item2 < item10)이고
// caseFirst로 대소문자 순서를, sensitivity로 대소문자·악센트 구분 여부를 바꿔요.
const options = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'word', title: '단어', width: 160 },
],
rows,
rowKey: 'id',
};
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();
}
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 } }),
};
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('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));
</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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.upper(api)}
>대문자 먼저</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.lower(api)}
>소문자 먼저</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.base(api)}
>대소문자 무시</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.plain(api)}
>숫자 자연순 끄기</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
word: string;
}
const rows: Row[] = ['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: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'word', title: '단어', width: 160 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'upper' } }),
lower: (api: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'lower' } }),
base: (api: GridApi<Row>) => api.setOptions({ sortCollator: { sensitivity: 'base' } }),
plain: (api: GridApi<Row>) => api.setOptions({ sortCollator: { numeric: false } }),
};버튼을 누르면 이 예제의 코드가 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">
<button type="button" :disabled="!api" @click="api && actions.upper(api)">대문자 먼저</button>
<button type="button" :disabled="!api" @click="api && actions.lower(api)">소문자 먼저</button>
<button type="button" :disabled="!api" @click="api && actions.base(api)">대소문자 무시</button>
<button type="button" :disabled="!api" @click="api && actions.plain(api)">숫자 자연순 끄기</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
word: string;
}
const rows: Row[] = ['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: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'word', title: '단어', width: 160 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'upper' } }),
lower: (api: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'lower' } }),
base: (api: GridApi<Row>) => api.setOptions({ sortCollator: { sensitivity: 'base' } }),
plain: (api: GridApi<Row>) => api.setOptions({ sortCollator: { numeric: false } }),
};버튼을 누르면 이 예제의 코드가 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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.upper(api)"
>대문자 먼저</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.lower(api)"
>소문자 먼저</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.base(api)"
>대소문자 무시</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.plain(api)"
>숫자 자연순 끄기</button>
</div>
<mx-grid style="height: 330px" [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 { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
word: string;
}
const rows: Row[] = ['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: GridOptions<Row> = {
columns: [
{ id: 'id', title: '번호', kind: 'number', width: 70 },
{ id: 'word', title: '단어', width: 160 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'upper' } }),
lower: (api: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'lower' } }),
base: (api: GridApi<Row>) => api.setOptions({ sortCollator: { sensitivity: 'base' } }),
plain: (api: GridApi<Row>) => api.setOptions({ sortCollator: { numeric: false } }),
};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="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>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));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 } }),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change the string ordering rules (collator)</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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.
const options = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'word', title: 'Word', width: 160 },
],
rows,
rowKey: 'id',
};
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();
}
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 } }),
};
options.ariaLabel = "Change the string ordering rules (collator)";
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('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));
</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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.upper(api)}
>Upper case first</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.lower(api)}
>Lower case first</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.base(api)}
>Ignore case</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.plain(api)}
>Natural numbers off</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
word: string;
}
const rows: Row[] = ['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: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'word', title: 'Word', width: 160 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'upper' } }),
lower: (api: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'lower' } }),
base: (api: GridApi<Row>) => api.setOptions({ sortCollator: { sensitivity: 'base' } }),
plain: (api: GridApi<Row>) => api.setOptions({ sortCollator: { numeric: false } }),
};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">
<button type="button" :disabled="!api" @click="api && actions.upper(api)">Upper case first</button>
<button type="button" :disabled="!api" @click="api && actions.lower(api)">Lower case first</button>
<button type="button" :disabled="!api" @click="api && actions.base(api)">Ignore case</button>
<button type="button" :disabled="!api" @click="api && actions.plain(api)">Natural numbers off</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
word: string;
}
const rows: Row[] = ['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: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'word', title: 'Word', width: 160 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'upper' } }),
lower: (api: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'lower' } }),
base: (api: GridApi<Row>) => api.setOptions({ sortCollator: { sensitivity: 'base' } }),
plain: (api: GridApi<Row>) => api.setOptions({ sortCollator: { numeric: false } }),
};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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.upper(api)"
>Upper case first</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.lower(api)"
>Lower case first</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.base(api)"
>Ignore case</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.plain(api)"
>Natural numbers off</button>
</div>
<mx-grid style="height: 330px" [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 { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
word: string;
}
const rows: Row[] = ['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: GridOptions<Row> = {
columns: [
{ id: 'id', title: 'No.', kind: 'number', width: 70 },
{ id: 'word', title: 'Word', width: 160 },
],
rows,
rowKey: 'id',
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'upper' } }),
lower: (api: GridApi<Row>) => api.setOptions({ sortCollator: { caseFirst: 'lower' } }),
base: (api: GridApi<Row>) => api.setOptions({ sortCollator: { sensitivity: 'base' } }),
plain: (api: GridApi<Row>) => api.setOptions({ sortCollator: { numeric: false } }),
};