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

용량·시간·금액·날짜를 읽기 쉽게 보여 주기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.

입문Beginner
직접 써 보기Live preview용량·시간·금액·날짜를 읽기 쉽게 보여 주기Readable sizes, durations, money 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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<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>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('sortSize').addEventListener('click', () => actions.sortSize(api));
example.js
// 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").',
    });
  },
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<div id="app">
  <div class="toolbar">
    <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>
main.js
import { createGrid } from 'maxgrid';
import { actions, options, setup } from './example';
const api = createGrid(document.getElementById('grid'), options);
setup(api, console.log);
document.getElementById('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('sortSize').addEventListener('click', () => actions.sortSize(api));
example.js
// 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").');
  },
};