용량·시간·금액·날짜를 읽기 쉽게 보여 주기Readable sizes, durations, money and dates
바이트를 KB·MB로, 초를 시:분:초로, 금액 뒤에 "원", 날짜를 한국어로 바꿔 보여 줘요. 값은 숫자 그대로라서 정렬은 원래 값으로 해요.Show bytes as KB/MB, seconds as h:mm:ss, money with a $ sign and dates in long English form. Values stay numbers, so sorting uses the real values.
코드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">
<select aria-label="숫자 보기" id="mode">
<option value="readable" selected>읽기 쉬운 단위</option>
<option value="raw">원래 숫자</option>
</select>
<button type="button" id="sortSize">크기 큰 순 정렬</button>
</div>
<div id="grid" style="height: 280px"></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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('sortSize').addEventListener('click', () => actions.sortSize(api));// formatValue는 저장된 값을 보여 줄 글자로 바꿔요. 값은 숫자·날짜 그대로라서 정렬·검색·내보내기는 원래 값으로 해요.
// 값이 비어 있으면(null) 빈 칸이나 "null" 대신 "—"를 보여 줘요.
function formatBytes(value) {
if (typeof value !== 'number' || !Number.isFinite(value))
return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value) {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)
return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const won = { format: (n) => `${n.toLocaleString('ko-KR')}원` };
const percent = new Intl.NumberFormat('ko-KR', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('ko-KR', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = () => [
{ id: 'file', title: '녹화 파일', width: 120 },
{
id: 'bytes',
title: '크기',
kind: 'number',
width: 140, // 원래 숫자(1450000000)가 말줄임되지 않을 폭
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: '길이',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: '전송 속도',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: '저장 요금',
kind: 'number',
width: 90,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? won.format(v) : '') : undefined,
},
{
id: 'ratio',
title: '압축률',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: '녹화일',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
export const options = {
columns: columns(),
rows: [
{
id: 1,
file: '월요일 회의.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 120,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: '전체 조회.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36250,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: '음성 메모.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: '제목 없음',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
say = log;
readable = true;
log({
ko: '크기는 B·KB·MB·GB로, 길이는 시:분:초로 읽기 쉽게 바꿔 보여요.',
en: 'Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.',
});
}
export const actions = {
mode: (api, value) => {
readable = value !== 'raw';
api.setColumns(columns());
say({
ko: readable ? '읽기 쉬운 단위로 보여요.' : '원래 숫자 그대로 보여요.',
en: readable ? 'Showing readable units.' : 'Showing the original numbers.',
});
},
sortSize: (api) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say({
ko: '크기가 큰 순으로 정렬했어요. 글자("1.4 GB")가 아니라 원래 숫자로 정렬해요.',
en: 'Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").',
});
},
};<!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">
<select aria-label="숫자 보기" id="mode">
<option value="readable" selected>읽기 쉬운 단위</option>
<option value="raw">원래 숫자</option>
</select>
<button type="button" id="sortSize">크기 큰 순 정렬</button>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// formatValue는 저장된 값을 보여 줄 글자로 바꿔요. 값은 숫자·날짜 그대로라서 정렬·검색·내보내기는 원래 값으로 해요.
// 값이 비어 있으면(null) 빈 칸이나 "null" 대신 "—"를 보여 줘요.
function formatBytes(value) {
if (typeof value !== 'number' || !Number.isFinite(value))
return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value) {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)
return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const won = { format: (n) => `${n.toLocaleString('ko-KR')}원` };
const percent = new Intl.NumberFormat('ko-KR', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('ko-KR', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = () => [
{ id: 'file', title: '녹화 파일', width: 120 },
{
id: 'bytes',
title: '크기',
kind: 'number',
width: 140, // 원래 숫자(1450000000)가 말줄임되지 않을 폭
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: '길이',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: '전송 속도',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: '저장 요금',
kind: 'number',
width: 90,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? won.format(v) : '') : undefined,
},
{
id: 'ratio',
title: '압축률',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: '녹화일',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
const options = {
columns: columns(),
rows: [
{
id: 1,
file: '월요일 회의.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 120,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: '전체 조회.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36250,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: '음성 메모.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: '제목 없음',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
function setup(_api, log) {
say = log;
readable = true;
log({
ko: '크기는 B·KB·MB·GB로, 길이는 시:분:초로 읽기 쉽게 바꿔 보여요.',
en: 'Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.',
});
}
const actions = {
mode: (api, value) => {
readable = value !== 'raw';
api.setColumns(columns());
say({
ko: readable ? '읽기 쉬운 단위로 보여요.' : '원래 숫자 그대로 보여요.',
en: readable ? 'Showing readable units.' : 'Showing the original numbers.',
});
},
sortSize: (api) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say({
ko: '크기가 큰 순으로 정렬했어요. 글자("1.4 GB")가 아니라 원래 숫자로 정렬해요.',
en: 'Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").',
});
},
};
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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('sortSize').addEventListener('click', () => actions.sortSize(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">
<select
aria-label="숫자 보기"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="readable">읽기 쉬운 단위</option>
<option value="raw">원래 숫자</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortSize(api)}
>크기 큰 순 정렬</button>
</div>
<Grid style={{ height: 280 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
file: string;
bytes: number;
seconds: number;
rate: number | null;
price: number;
ratio: number;
at: Date;
}
// formatValue는 저장된 값을 보여 줄 글자로 바꿔요. 값은 숫자·날짜 그대로라서 정렬·검색·내보내기는 원래 값으로 해요.
// 값이 비어 있으면(null) 빈 칸이나 "null" 대신 "—"를 보여 줘요.
function formatBytes(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value)) return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n: number) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const won = { format: (n: number): string => `${n.toLocaleString('ko-KR')}원` };
const percent = new Intl.NumberFormat('ko-KR', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('ko-KR', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'file', title: '녹화 파일', width: 120 },
{
id: 'bytes',
title: '크기',
kind: 'number',
width: 140, // 원래 숫자(1450000000)가 말줄임되지 않을 폭
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: '길이',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: '전송 속도',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: '저장 요금',
kind: 'number',
width: 90,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? won.format(v) : '') : undefined,
},
{
id: 'ratio',
title: '압축률',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: '녹화일',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{
id: 1,
file: '월요일 회의.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 120,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: '전체 조회.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36250,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: '음성 메모.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: '제목 없음',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
readable = true;
log({
ko: '크기는 B·KB·MB·GB로, 길이는 시:분:초로 읽기 쉽게 바꿔 보여요.',
en: 'Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.',
});
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
readable = value !== 'raw';
api.setColumns(columns());
say({
ko: readable ? '읽기 쉬운 단위로 보여요.' : '원래 숫자 그대로 보여요.',
en: readable ? 'Showing readable units.' : 'Showing the original numbers.',
});
},
sortSize: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say({
ko: '크기가 큰 순으로 정렬했어요. 글자("1.4 GB")가 아니라 원래 숫자로 정렬해요.',
en: 'Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").',
});
},
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="숫자 보기"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="readable" selected>읽기 쉬운 단위</option>
<option value="raw">원래 숫자</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.sortSize(api)"
>크기 큰 순 정렬</button>
</div>
<Grid style="height: 280px" :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;
file: string;
bytes: number;
seconds: number;
rate: number | null;
price: number;
ratio: number;
at: Date;
}
// formatValue는 저장된 값을 보여 줄 글자로 바꿔요. 값은 숫자·날짜 그대로라서 정렬·검색·내보내기는 원래 값으로 해요.
// 값이 비어 있으면(null) 빈 칸이나 "null" 대신 "—"를 보여 줘요.
function formatBytes(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value)) return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n: number) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const won = { format: (n: number): string => `${n.toLocaleString('ko-KR')}원` };
const percent = new Intl.NumberFormat('ko-KR', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('ko-KR', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'file', title: '녹화 파일', width: 120 },
{
id: 'bytes',
title: '크기',
kind: 'number',
width: 140, // 원래 숫자(1450000000)가 말줄임되지 않을 폭
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: '길이',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: '전송 속도',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: '저장 요금',
kind: 'number',
width: 90,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? won.format(v) : '') : undefined,
},
{
id: 'ratio',
title: '압축률',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: '녹화일',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{
id: 1,
file: '월요일 회의.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 120,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: '전체 조회.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36250,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: '음성 메모.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: '제목 없음',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
readable = true;
log({
ko: '크기는 B·KB·MB·GB로, 길이는 시:분:초로 읽기 쉽게 바꿔 보여요.',
en: 'Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.',
});
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
readable = value !== 'raw';
api.setColumns(columns());
say({
ko: readable ? '읽기 쉬운 단위로 보여요.' : '원래 숫자 그대로 보여요.',
en: readable ? 'Showing readable units.' : 'Showing the original numbers.',
});
},
sortSize: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say({
ko: '크기가 큰 순으로 정렬했어요. 글자("1.4 GB")가 아니라 원래 숫자로 정렬해요.',
en: 'Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").',
});
},
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="숫자 보기"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="readable" selected>읽기 쉬운 단위</option>
<option value="raw">원래 숫자</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortSize(api)"
>크기 큰 순 정렬</button>
</div>
<mx-grid style="height: 280px" [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;
file: string;
bytes: number;
seconds: number;
rate: number | null;
price: number;
ratio: number;
at: Date;
}
// formatValue는 저장된 값을 보여 줄 글자로 바꿔요. 값은 숫자·날짜 그대로라서 정렬·검색·내보내기는 원래 값으로 해요.
// 값이 비어 있으면(null) 빈 칸이나 "null" 대신 "—"를 보여 줘요.
function formatBytes(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value)) return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n: number) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const won = { format: (n: number): string => `${n.toLocaleString('ko-KR')}원` };
const percent = new Intl.NumberFormat('ko-KR', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('ko-KR', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'file', title: '녹화 파일', width: 120 },
{
id: 'bytes',
title: '크기',
kind: 'number',
width: 140, // 원래 숫자(1450000000)가 말줄임되지 않을 폭
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: '길이',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: '전송 속도',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: '저장 요금',
kind: 'number',
width: 90,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? won.format(v) : '') : undefined,
},
{
id: 'ratio',
title: '압축률',
kind: 'number',
width: 70,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: '녹화일',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{
id: 1,
file: '월요일 회의.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 120,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: '전체 조회.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36250,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: '음성 메모.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: '제목 없음',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
readable = true;
log({
ko: '크기는 B·KB·MB·GB로, 길이는 시:분:초로 읽기 쉽게 바꿔 보여요.',
en: 'Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.',
});
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
readable = value !== 'raw';
api.setColumns(columns());
say({
ko: readable ? '읽기 쉬운 단위로 보여요.' : '원래 숫자 그대로 보여요.',
en: readable ? 'Showing readable units.' : 'Showing the original numbers.',
});
},
sortSize: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say({
ko: '크기가 큰 순으로 정렬했어요. 글자("1.4 GB")가 아니라 원래 숫자로 정렬해요.',
en: 'Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").',
});
},
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Number display" id="mode">
<option value="readable" selected>Readable units</option>
<option value="raw">Raw numbers</option>
</select>
<button type="button" id="sortSize">Sort by size</button>
</div>
<div id="grid" style="height: 280px"></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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('sortSize').addEventListener('click', () => actions.sortSize(api));// formatValue turns the stored value into display text. The value stays a number or date, so sort, search and export use the original value.
// An empty value (null) shows "—" instead of a blank or "null".
function formatBytes(value) {
if (typeof value !== 'number' || !Number.isFinite(value))
return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value) {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)
return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const money = {
format: (n) => n.toLocaleString('en-US', { style: 'currency', currency: 'USD' }),
};
const percent = new Intl.NumberFormat('en-US', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = () => [
{ id: 'file', title: 'Recording', width: 120 },
{
id: 'bytes',
title: 'Size',
kind: 'number',
width: 140, // wide enough that the raw number (1450000000) is not truncated
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: 'Length',
kind: 'number',
width: 100,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: 'Bitrate',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: 'Storage fee',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? money.format(v) : '') : undefined,
},
{
id: 'ratio',
title: 'Compression',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: 'Recorded',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
export const options = {
columns: columns(),
rows: [
{
id: 1,
file: 'Monday meeting.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 0.12,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: 'All-hands.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36.25,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: 'Voice memo.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: 'Untitled',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
export function setup(_api, log) {
say = log;
readable = true;
log('Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.');
}
export const actions = {
mode: (api, value) => {
readable = value !== 'raw';
api.setColumns(columns());
say(readable ? 'Showing readable units.' : 'Showing the original numbers.');
},
sortSize: (api) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say('Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").');
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Readable sizes, durations, money and dates</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Number display" id="mode">
<option value="readable" selected>Readable units</option>
<option value="raw">Raw numbers</option>
</select>
<button type="button" id="sortSize">Sort by size</button>
</div>
<div id="grid" style="height: 280px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// formatValue turns the stored value into display text. The value stays a number or date, so sort, search and export use the original value.
// An empty value (null) shows "—" instead of a blank or "null".
function formatBytes(value) {
if (typeof value !== 'number' || !Number.isFinite(value))
return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value) {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0)
return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const money = {
format: (n) => n.toLocaleString('en-US', { style: 'currency', currency: 'USD' }),
};
const percent = new Intl.NumberFormat('en-US', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = () => [
{ id: 'file', title: 'Recording', width: 120 },
{
id: 'bytes',
title: 'Size',
kind: 'number',
width: 140, // wide enough that the raw number (1450000000) is not truncated
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: 'Length',
kind: 'number',
width: 100,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: 'Bitrate',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: 'Storage fee',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? money.format(v) : '') : undefined,
},
{
id: 'ratio',
title: 'Compression',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: 'Recorded',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
const options = {
columns: columns(),
rows: [
{
id: 1,
file: 'Monday meeting.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 0.12,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: 'All-hands.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36.25,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: 'Voice memo.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: 'Untitled',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say = () => { };
function setup(_api, log) {
say = log;
readable = true;
log('Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.');
}
const actions = {
mode: (api, value) => {
readable = value !== 'raw';
api.setColumns(columns());
say(readable ? 'Showing readable units.' : 'Showing the original numbers.');
},
sortSize: (api) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say('Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").');
},
};
options.ariaLabel = "Readable sizes, durations, money and dates";
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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('sortSize').addEventListener('click', () => actions.sortSize(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">
<select
aria-label="Number display"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="readable">Readable units</option>
<option value="raw">Raw numbers</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.sortSize(api)}
>Sort by size</button>
</div>
<Grid style={{ height: 280 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
file: string;
bytes: number;
seconds: number;
rate: number | null;
price: number;
ratio: number;
at: Date;
}
// formatValue turns the stored value into display text. The value stays a number or date, so sort, search and export use the original value.
// An empty value (null) shows "—" instead of a blank or "null".
function formatBytes(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value)) return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n: number) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const money = {
format: (n: number): string => n.toLocaleString('en-US', { style: 'currency', currency: 'USD' }),
};
const percent = new Intl.NumberFormat('en-US', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'file', title: 'Recording', width: 120 },
{
id: 'bytes',
title: 'Size',
kind: 'number',
width: 140, // wide enough that the raw number (1450000000) is not truncated
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: 'Length',
kind: 'number',
width: 100,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: 'Bitrate',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: 'Storage fee',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? money.format(v) : '') : undefined,
},
{
id: 'ratio',
title: 'Compression',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: 'Recorded',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{
id: 1,
file: 'Monday meeting.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 0.12,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: 'All-hands.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36.25,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: 'Voice memo.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: 'Untitled',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
readable = true;
log('Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.');
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
readable = value !== 'raw';
api.setColumns(columns());
say(readable ? 'Showing readable units.' : 'Showing the original numbers.');
},
sortSize: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say(
'Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").',
);
},
};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">
<select
aria-label="Number display"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="readable" selected>Readable units</option>
<option value="raw">Raw numbers</option>
</select>
<button
type="button"
:disabled="!api"
@click="api && actions.sortSize(api)"
>Sort by size</button>
</div>
<Grid style="height: 280px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
file: string;
bytes: number;
seconds: number;
rate: number | null;
price: number;
ratio: number;
at: Date;
}
// formatValue turns the stored value into display text. The value stays a number or date, so sort, search and export use the original value.
// An empty value (null) shows "—" instead of a blank or "null".
function formatBytes(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value)) return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n: number) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const money = {
format: (n: number): string => n.toLocaleString('en-US', { style: 'currency', currency: 'USD' }),
};
const percent = new Intl.NumberFormat('en-US', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'file', title: 'Recording', width: 120 },
{
id: 'bytes',
title: 'Size',
kind: 'number',
width: 140, // wide enough that the raw number (1450000000) is not truncated
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: 'Length',
kind: 'number',
width: 100,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: 'Bitrate',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: 'Storage fee',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? money.format(v) : '') : undefined,
},
{
id: 'ratio',
title: 'Compression',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: 'Recorded',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{
id: 1,
file: 'Monday meeting.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 0.12,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: 'All-hands.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36.25,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: 'Voice memo.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: 'Untitled',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
readable = true;
log('Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.');
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
readable = value !== 'raw';
api.setColumns(columns());
say(readable ? 'Showing readable units.' : 'Showing the original numbers.');
},
sortSize: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say(
'Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").',
);
},
};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">
<select
aria-label="Number display"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="readable" selected>Readable units</option>
<option value="raw">Raw numbers</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.sortSize(api)"
>Sort by size</button>
</div>
<mx-grid style="height: 280px" [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;
export interface Row {
id: number;
file: string;
bytes: number;
seconds: number;
rate: number | null;
price: number;
ratio: number;
at: Date;
}
// formatValue turns the stored value into display text. The value stays a number or date, so sort, search and export use the original value.
// An empty value (null) shows "—" instead of a blank or "null".
function formatBytes(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value)) return '';
const units = ['B', 'KB', 'MB', 'GB', 'TB'];
let size = value;
let unit = 0;
while (size >= 1024 && unit < units.length - 1) {
size /= 1024;
unit += 1;
}
return `${unit === 0 ? size : size.toFixed(1)} ${units[unit]}`;
}
function formatDuration(value: unknown): string {
if (typeof value !== 'number' || !Number.isFinite(value) || value < 0) return '';
const h = Math.floor(value / 3600);
const m = Math.floor((value % 3600) / 60);
const s = Math.floor(value % 60);
const pad = (n: number) => String(n).padStart(2, '0');
return h > 0 ? `${h}:${pad(m)}:${pad(s)}` : `${m}:${pad(s)}`;
}
const money = {
format: (n: number): string => n.toLocaleString('en-US', { style: 'currency', currency: 'USD' }),
};
const percent = new Intl.NumberFormat('en-US', { style: 'percent', minimumFractionDigits: 1 });
const day = new Intl.DateTimeFormat('en-US', { year: 'numeric', month: 'long', day: 'numeric' });
let readable = true;
const columns = (): NonNullable<GridOptions<Row>['columns']> => [
{ id: 'file', title: 'Recording', width: 120 },
{
id: 'bytes',
title: 'Size',
kind: 'number',
width: 140, // wide enough that the raw number (1450000000) is not truncated
align: 'end',
formatValue: readable ? formatBytes : undefined,
},
{
id: 'seconds',
title: 'Length',
kind: 'number',
width: 100,
align: 'end',
formatValue: readable ? formatDuration : undefined,
},
{
id: 'rate',
title: 'Bitrate',
kind: 'number',
width: 95,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? `${v} kbps` : '—') : undefined,
},
{
id: 'price',
title: 'Storage fee',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? money.format(v) : '') : undefined,
},
{
id: 'ratio',
title: 'Compression',
kind: 'number',
width: 140,
align: 'end',
formatValue: readable ? (v) => (typeof v === 'number' ? percent.format(v) : '') : undefined,
},
{
id: 'at',
title: 'Recorded',
kind: 'date',
width: 120,
formatValue: readable ? (v) => (v instanceof Date ? day.format(v) : '') : undefined,
},
];
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{
id: 1,
file: 'Monday meeting.m4a',
bytes: 4_800_000,
seconds: 912,
rate: 128,
price: 0.12,
ratio: 0.412,
at: new Date(2026, 10, 2),
},
{
id: 2,
file: 'All-hands.mp4',
bytes: 1_450_000_000,
seconds: 3725,
rate: 3200,
price: 36.25,
ratio: 0.087,
at: new Date(2026, 9, 28),
},
{
id: 3,
file: 'Voice memo.opus',
bytes: 38_400,
seconds: 47,
rate: 64,
price: 1,
ratio: 0.5,
at: new Date(2026, 10, 5),
},
{
id: 4,
file: 'Untitled',
bytes: 0,
seconds: 0,
rate: null,
price: 0,
ratio: 0,
at: new Date(2026, 10, 6),
},
],
rowKey: 'id',
saveMode: 'none',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
readable = true;
log('Sizes show as B, KB, MB, GB and lengths as h:m:s so they are easy to read.');
}
export const actions = {
mode: (api: GridApi<Row>, value?: string) => {
readable = value !== 'raw';
api.setColumns(columns());
say(readable ? 'Showing readable units.' : 'Showing the original numbers.');
},
sortSize: (api: GridApi<Row>) => {
api.setSortModel([{ columnId: 'bytes', direction: 'desc' }]);
say(
'Sorted by size, largest first. Sorting uses the original number, not the text ("1.4 GB").',
);
},
};