값을 원·%·kg·날짜로 보여 주기Show values as dollars, percent, kg and dates
숫자와 날짜를 읽기 좋은 글자로 바꿔 보여 줘요. 보이는 모양만 바뀌고 원래 값은 그대로라서 정렬과 필터는 숫자·날짜 기준으로 정확히 동작해요.Numbers and dates are shown as readable text. Only the display changes; the raw value stays, so sorting and filtering still work on numbers and dates.
코드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="distanceAsc">배송 거리 오름차순</button>
<button type="button" id="priceDesc">단가 내림차순</button>
<button type="button" id="clear">정렬 해제</button>
</div>
<div id="grid" style="height: 210px"></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('distanceAsc').addEventListener('click', () => actions.distanceAsc(api));
document.getElementById('priceDesc').addEventListener('click', () => actions.priceDesc(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));// formatValue는 보이는 글자만 바꿔요. 정렬·필터·내보내기는 원래 값(숫자, 날짜)을 그대로 써요.
const won = (value) => `${Number(value).toLocaleString('ko-KR')}원`;
const percent = (value) => `${(Number(value) * 100).toFixed(1)}%`;
const unit = (suffix) => (value) => value == null ? '' : `${Number(value).toLocaleString('ko-KR')}${suffix}`;
const day = (value) => value instanceof Date
? `${value.getFullYear()}년 ${value.getMonth() + 1}월 ${value.getDate()}일`
: '';
export const options = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'price', title: '단가', kind: 'number', width: 120, align: 'end', formatValue: won },
{
id: 'margin',
title: '마진율',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: '무게',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: '배송 거리',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: '출고일', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: '철제 선반',
price: 128000,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: '핸드 파레트 트럭',
price: 459000,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: '스트레치 필름',
price: 38500,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: '라벨 프린터',
price: 289000,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
export const actions = {
// 거리를 글자로 보면 '1,204km'가 '312km'보다 앞이지만, 원래 값(숫자)으로 정렬해서 312가 먼저 와요.
distanceAsc: (api) => api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
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>값을 원·%·kg·날짜로 보여 주기</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="distanceAsc">배송 거리 오름차순</button>
<button type="button" id="priceDesc">단가 내림차순</button>
<button type="button" id="clear">정렬 해제</button>
</div>
<div id="grid" style="height: 210px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// formatValue는 보이는 글자만 바꿔요. 정렬·필터·내보내기는 원래 값(숫자, 날짜)을 그대로 써요.
const won = (value) => `${Number(value).toLocaleString('ko-KR')}원`;
const percent = (value) => `${(Number(value) * 100).toFixed(1)}%`;
const unit = (suffix) => (value) => value == null ? '' : `${Number(value).toLocaleString('ko-KR')}${suffix}`;
const day = (value) => value instanceof Date
? `${value.getFullYear()}년 ${value.getMonth() + 1}월 ${value.getDate()}일`
: '';
const options = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'price', title: '단가', kind: 'number', width: 120, align: 'end', formatValue: won },
{
id: 'margin',
title: '마진율',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: '무게',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: '배송 거리',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: '출고일', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: '철제 선반',
price: 128000,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: '핸드 파레트 트럭',
price: 459000,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: '스트레치 필름',
price: 38500,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: '라벨 프린터',
price: 289000,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
const actions = {
// 거리를 글자로 보면 '1,204km'가 '312km'보다 앞이지만, 원래 값(숫자)으로 정렬해서 312가 먼저 와요.
distanceAsc: (api) => api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api) => api.setSortModel([]),
};
options.ariaLabel = "값을 원·%·kg·날짜로 보여 주기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('distanceAsc').addEventListener('click', () => actions.distanceAsc(api));
document.getElementById('priceDesc').addEventListener('click', () => actions.priceDesc(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.distanceAsc(api)}
>배송 거리 오름차순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.priceDesc(api)}
>단가 내림차순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>정렬 해제</button>
</div>
<Grid style={{ height: 210 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
item: string;
price: number;
margin: number;
weightKg: number;
distanceKm: number;
shipped: Date;
}
// formatValue는 보이는 글자만 바꿔요. 정렬·필터·내보내기는 원래 값(숫자, 날짜)을 그대로 써요.
const won = (value: unknown): string => `${Number(value).toLocaleString('ko-KR')}원`;
const percent = (value: unknown): string => `${(Number(value) * 100).toFixed(1)}%`;
const unit =
(suffix: string) =>
(value: unknown): string =>
value == null ? '' : `${Number(value).toLocaleString('ko-KR')}${suffix}`;
const day = (value: unknown): string =>
value instanceof Date
? `${value.getFullYear()}년 ${value.getMonth() + 1}월 ${value.getDate()}일`
: '';
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'price', title: '단가', kind: 'number', width: 120, align: 'end', formatValue: won },
{
id: 'margin',
title: '마진율',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: '무게',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: '배송 거리',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: '출고일', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: '철제 선반',
price: 128000,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: '핸드 파레트 트럭',
price: 459000,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: '스트레치 필름',
price: 38500,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: '라벨 프린터',
price: 289000,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
export const actions = {
// 거리를 글자로 보면 '1,204km'가 '312km'보다 앞이지만, 원래 값(숫자)으로 정렬해서 312가 먼저 와요.
distanceAsc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
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.distanceAsc(api)"
>배송 거리 오름차순</button>
<button
type="button"
:disabled="!api"
@click="api && actions.priceDesc(api)"
>단가 내림차순</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">정렬 해제</button>
</div>
<Grid style="height: 210px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
item: string;
price: number;
margin: number;
weightKg: number;
distanceKm: number;
shipped: Date;
}
// formatValue는 보이는 글자만 바꿔요. 정렬·필터·내보내기는 원래 값(숫자, 날짜)을 그대로 써요.
const won = (value: unknown): string => `${Number(value).toLocaleString('ko-KR')}원`;
const percent = (value: unknown): string => `${(Number(value) * 100).toFixed(1)}%`;
const unit =
(suffix: string) =>
(value: unknown): string =>
value == null ? '' : `${Number(value).toLocaleString('ko-KR')}${suffix}`;
const day = (value: unknown): string =>
value instanceof Date
? `${value.getFullYear()}년 ${value.getMonth() + 1}월 ${value.getDate()}일`
: '';
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'price', title: '단가', kind: 'number', width: 120, align: 'end', formatValue: won },
{
id: 'margin',
title: '마진율',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: '무게',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: '배송 거리',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: '출고일', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: '철제 선반',
price: 128000,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: '핸드 파레트 트럭',
price: 459000,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: '스트레치 필름',
price: 38500,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: '라벨 프린터',
price: 289000,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
export const actions = {
// 거리를 글자로 보면 '1,204km'가 '312km'보다 앞이지만, 원래 값(숫자)으로 정렬해서 312가 먼저 와요.
distanceAsc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
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.distanceAsc(api)"
>배송 거리 오름차순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.priceDesc(api)"
>단가 내림차순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>정렬 해제</button>
</div>
<mx-grid style="height: 210px" [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;
item: string;
price: number;
margin: number;
weightKg: number;
distanceKm: number;
shipped: Date;
}
// formatValue는 보이는 글자만 바꿔요. 정렬·필터·내보내기는 원래 값(숫자, 날짜)을 그대로 써요.
const won = (value: unknown): string => `${Number(value).toLocaleString('ko-KR')}원`;
const percent = (value: unknown): string => `${(Number(value) * 100).toFixed(1)}%`;
const unit =
(suffix: string) =>
(value: unknown): string =>
value == null ? '' : `${Number(value).toLocaleString('ko-KR')}${suffix}`;
const day = (value: unknown): string =>
value instanceof Date
? `${value.getFullYear()}년 ${value.getMonth() + 1}월 ${value.getDate()}일`
: '';
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: '품목', width: 140 },
{ id: 'price', title: '단가', kind: 'number', width: 120, align: 'end', formatValue: won },
{
id: 'margin',
title: '마진율',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: '무게',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: '배송 거리',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: '출고일', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: '철제 선반',
price: 128000,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: '핸드 파레트 트럭',
price: 459000,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: '스트레치 필름',
price: 38500,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: '라벨 프린터',
price: 289000,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
export const actions = {
// 거리를 글자로 보면 '1,204km'가 '312km'보다 앞이지만, 원래 값(숫자)으로 정렬해서 312가 먼저 와요.
distanceAsc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
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="distanceAsc">Distance ascending</button>
<button type="button" id="priceDesc">Price descending</button>
<button type="button" id="clear">Clear sort</button>
</div>
<div id="grid" style="height: 210px"></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('distanceAsc').addEventListener('click', () => actions.distanceAsc(api));
document.getElementById('priceDesc').addEventListener('click', () => actions.priceDesc(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));// formatValue changes only the visible text. Sorting, filtering and export keep using the original value (number, date).
const money = (value) => `$${Number(value).toLocaleString('en-US')}`;
const percent = (value) => `${(Number(value) * 100).toFixed(1)}%`;
const unit = (suffix) => (value) => value == null ? '' : `${Number(value).toLocaleString('en-US')}${suffix}`;
const day = (value) => value instanceof Date
? `${String(value.getMonth() + 1).padStart(2, '0')}/${String(value.getDate()).padStart(2, '0')}/${value.getFullYear()}`
: '';
export const options = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'price', title: 'Price', kind: 'number', width: 120, align: 'end', formatValue: money },
{
id: 'margin',
title: 'Margin',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: 'Weight',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: 'Distance',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: 'Shipped', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: 'Steel Shelf',
price: 128,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: 'Hand Pallet Truck',
price: 459,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: 'Stretch Film',
price: 39,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: 'Label Printer',
price: 289,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
export const actions = {
// As text, '1,204km' would come before '312km', but the sort uses the original value (a number), so 312 comes first.
distanceAsc: (api) => api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
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>Show values as dollars, percent, kg and dates</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="distanceAsc">Distance ascending</button>
<button type="button" id="priceDesc">Price descending</button>
<button type="button" id="clear">Clear sort</button>
</div>
<div id="grid" style="height: 210px"></div>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// formatValue changes only the visible text. Sorting, filtering and export keep using the original value (number, date).
const money = (value) => `$${Number(value).toLocaleString('en-US')}`;
const percent = (value) => `${(Number(value) * 100).toFixed(1)}%`;
const unit = (suffix) => (value) => value == null ? '' : `${Number(value).toLocaleString('en-US')}${suffix}`;
const day = (value) => value instanceof Date
? `${String(value.getMonth() + 1).padStart(2, '0')}/${String(value.getDate()).padStart(2, '0')}/${value.getFullYear()}`
: '';
const options = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'price', title: 'Price', kind: 'number', width: 120, align: 'end', formatValue: money },
{
id: 'margin',
title: 'Margin',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: 'Weight',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: 'Distance',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: 'Shipped', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: 'Steel Shelf',
price: 128,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: 'Hand Pallet Truck',
price: 459,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: 'Stretch Film',
price: 39,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: 'Label Printer',
price: 289,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
const actions = {
// As text, '1,204km' would come before '312km', but the sort uses the original value (a number), so 312 comes first.
distanceAsc: (api) => api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api) => api.setSortModel([]),
};
options.ariaLabel = "Show values as dollars, percent, kg and dates";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
document.getElementById('distanceAsc').addEventListener('click', () => actions.distanceAsc(api));
document.getElementById('priceDesc').addEventListener('click', () => actions.priceDesc(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.distanceAsc(api)}
>Distance ascending</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.priceDesc(api)}
>Price descending</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear sort</button>
</div>
<Grid style={{ height: 210 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
item: string;
price: number;
margin: number;
weightKg: number;
distanceKm: number;
shipped: Date;
}
// formatValue changes only the visible text. Sorting, filtering and export keep using the original value (number, date).
const money = (value: unknown): string => `$${Number(value).toLocaleString('en-US')}`;
const percent = (value: unknown): string => `${(Number(value) * 100).toFixed(1)}%`;
const unit =
(suffix: string) =>
(value: unknown): string =>
value == null ? '' : `${Number(value).toLocaleString('en-US')}${suffix}`;
const day = (value: unknown): string =>
value instanceof Date
? `${String(value.getMonth() + 1).padStart(2, '0')}/${String(value.getDate()).padStart(2, '0')}/${value.getFullYear()}`
: '';
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'price', title: 'Price', kind: 'number', width: 120, align: 'end', formatValue: money },
{
id: 'margin',
title: 'Margin',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: 'Weight',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: 'Distance',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: 'Shipped', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: 'Steel Shelf',
price: 128,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: 'Hand Pallet Truck',
price: 459,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: 'Stretch Film',
price: 39,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: 'Label Printer',
price: 289,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
export const actions = {
// As text, '1,204km' would come before '312km', but the sort uses the original value (a number), so 312 comes first.
distanceAsc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
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.distanceAsc(api)"
>Distance ascending</button>
<button
type="button"
:disabled="!api"
@click="api && actions.priceDesc(api)"
>Price descending</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear sort</button>
</div>
<Grid style="height: 210px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
item: string;
price: number;
margin: number;
weightKg: number;
distanceKm: number;
shipped: Date;
}
// formatValue changes only the visible text. Sorting, filtering and export keep using the original value (number, date).
const money = (value: unknown): string => `$${Number(value).toLocaleString('en-US')}`;
const percent = (value: unknown): string => `${(Number(value) * 100).toFixed(1)}%`;
const unit =
(suffix: string) =>
(value: unknown): string =>
value == null ? '' : `${Number(value).toLocaleString('en-US')}${suffix}`;
const day = (value: unknown): string =>
value instanceof Date
? `${String(value.getMonth() + 1).padStart(2, '0')}/${String(value.getDate()).padStart(2, '0')}/${value.getFullYear()}`
: '';
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'price', title: 'Price', kind: 'number', width: 120, align: 'end', formatValue: money },
{
id: 'margin',
title: 'Margin',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: 'Weight',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: 'Distance',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: 'Shipped', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: 'Steel Shelf',
price: 128,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: 'Hand Pallet Truck',
price: 459,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: 'Stretch Film',
price: 39,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: 'Label Printer',
price: 289,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
export const actions = {
// As text, '1,204km' would come before '312km', but the sort uses the original value (a number), so 312 comes first.
distanceAsc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
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.distanceAsc(api)"
>Distance ascending</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.priceDesc(api)"
>Price descending</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear sort</button>
</div>
<mx-grid style="height: 210px" [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;
item: string;
price: number;
margin: number;
weightKg: number;
distanceKm: number;
shipped: Date;
}
// formatValue changes only the visible text. Sorting, filtering and export keep using the original value (number, date).
const money = (value: unknown): string => `$${Number(value).toLocaleString('en-US')}`;
const percent = (value: unknown): string => `${(Number(value) * 100).toFixed(1)}%`;
const unit =
(suffix: string) =>
(value: unknown): string =>
value == null ? '' : `${Number(value).toLocaleString('en-US')}${suffix}`;
const day = (value: unknown): string =>
value instanceof Date
? `${String(value.getMonth() + 1).padStart(2, '0')}/${String(value.getDate()).padStart(2, '0')}/${value.getFullYear()}`
: '';
export const options: GridOptions<Row> = {
columns: [
{ id: 'item', title: 'Item', width: 140 },
{ id: 'price', title: 'Price', kind: 'number', width: 120, align: 'end', formatValue: money },
{
id: 'margin',
title: 'Margin',
kind: 'number',
width: 100,
align: 'end',
formatValue: percent,
},
{
id: 'weightKg',
title: 'Weight',
kind: 'number',
width: 100,
align: 'end',
formatValue: unit('kg'),
},
{
id: 'distanceKm',
title: 'Distance',
kind: 'number',
width: 120,
align: 'end',
formatValue: unit('km'),
},
{ id: 'shipped', title: 'Shipped', kind: 'date', width: 140, formatValue: day },
],
rows: [
{
id: 1,
item: 'Steel Shelf',
price: 128,
margin: 0.182,
weightKg: 24.5,
distanceKm: 312,
shipped: new Date(2026, 2, 4),
},
{
id: 2,
item: 'Hand Pallet Truck',
price: 459,
margin: 0.231,
weightKg: 78,
distanceKm: 1204,
shipped: new Date(2026, 2, 18),
},
{
id: 3,
item: 'Stretch Film',
price: 39,
margin: 0.095,
weightKg: 12.2,
distanceKm: 45.5,
shipped: new Date(2026, 3, 2),
},
{
id: 4,
item: 'Label Printer',
price: 289,
margin: 0.156,
weightKg: 3.4,
distanceKm: 98,
shipped: new Date(2026, 1, 25),
},
],
rowKey: 'id',
};
export const actions = {
// As text, '1,204km' would come before '312km', but the sort uses the original value (a number), so 312 comes first.
distanceAsc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'distanceKm', direction: 'asc' }]),
priceDesc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'price', direction: 'desc' }]),
clear: (api: GridApi<Row>) => api.setSortModel([]),
};