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

값을 원·%·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.

입문Beginner
직접 써 보기Live preview값을 원·%·kg·날짜로 보여 주기Show values as dollars, percent, kg 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">
    <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>
main.js
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));
example.js
// 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([]),
};

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

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

index.html
<div id="app">
  <div class="toolbar">
    <button type="button" id="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>
main.js
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));
example.js
// 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([]),
};