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

날짜 정렬: 시각은 무시, 빈 값은 맨 뒤Date sorting: ignore time, empty values last

날짜 컬럼은 몇 시에 주문했는지와 상관없이 날짜만 비교해요. 같은 날 주문은 원래 순서를 지키고, 배송일이 아직 없는 주문은 오름차순·내림차순 어느 쪽으로 정렬해도 맨 뒤에 모여요.Date columns compare calendar dates only, so orders from the same day keep their original order, and rows with no ship date stay at the end in both directions.

입문Beginner
직접 써 보기Live preview날짜 정렬: 시각은 무시, 빈 값은 맨 뒤Date sorting: ignore time, empty values last

코드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="oldestFirst">주문일 빠른 순</button>
    <button type="button" id="newestFirst">주문일 늦은 순</button>
    <button type="button" id="shippedAsc">배송일 오름차순</button>
    <button type="button" id="shippedDesc">배송일 내림차순</button>
    <button type="button" id="clear">정렬 해제</button>
  </div>
  <div id="grid" style="height: 340px"></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('oldestFirst').addEventListener('click', () => actions.oldestFirst(api));
document.getElementById('newestFirst').addEventListener('click', () => actions.newestFirst(api));
document.getElementById('shippedAsc').addEventListener('click', () => actions.shippedAsc(api));
document.getElementById('shippedDesc').addEventListener('click', () => actions.shippedDesc(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const text = (value) => value instanceof Date
  ? `${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}`
  : '';
// 날짜 컬럼은 달력 날짜로 비교해요. 시각은 무시해서 같은 날 주문은 원래 순서를 지키고,
// 배송일이 비어 있는 행은 오름차순이든 내림차순이든 항상 맨 뒤에 있어요.
export const options = {
  columns: [
    { id: 'order', title: '주문 번호', width: 120 },
    {
      id: 'ordered',
      title: '주문일 (시각 포함)',
      kind: 'date',
      width: 190,
      formatValue: (value) => value instanceof Date
        ? `${text(value)} ${String(value.getHours()).padStart(2, '0')}:${String(value.getMinutes()).padStart(2, '0')}`
        : '',
    },
    {
      id: 'shipped',
      title: '배송일',
      kind: 'date',
      width: 130,
      formatValue: (value) => text(value),
    },
  ],
  rows: [
    {
      id: 1,
      order: 'SO-1001',
      ordered: new Date(2026, 2, 5, 23, 40),
      shipped: new Date(2026, 2, 7),
    },
    { id: 2, order: 'SO-1002', ordered: new Date(2026, 2, 5, 8, 10), shipped: null },
    {
      id: 3,
      order: 'SO-1003',
      ordered: new Date(2026, 0, 28, 14, 0),
      shipped: new Date(2026, 1, 2),
    },
    {
      id: 4,
      order: 'SO-1004',
      ordered: new Date(2026, 1, 14, 9, 30),
      shipped: new Date(2026, 1, 16),
    },
    {
      id: 5,
      order: 'SO-1005',
      ordered: new Date(2025, 11, 30, 18, 5),
      shipped: new Date(2026, 0, 3),
    },
    { id: 6, order: 'SO-1006', ordered: new Date(2026, 3, 1, 11, 45), shipped: null },
    {
      id: 7,
      order: 'SO-1007',
      ordered: new Date(2026, 2, 19, 16, 20),
      shipped: new Date(2026, 2, 21),
    },
  ],
  rowKey: 'id',
};
export const actions = {
  oldestFirst: (api) => api.setSortModel([{ columnId: 'ordered', direction: 'asc' }]),
  newestFirst: (api) => api.setSortModel([{ columnId: 'ordered', direction: 'desc' }]),
  shippedAsc: (api) => api.setSortModel([{ columnId: 'shipped', direction: 'asc' }]),
  shippedDesc: (api) => api.setSortModel([{ columnId: 'shipped', 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="oldestFirst">Oldest order first</button>
    <button type="button" id="newestFirst">Newest order first</button>
    <button type="button" id="shippedAsc">Shipped ascending</button>
    <button type="button" id="shippedDesc">Shipped descending</button>
    <button type="button" id="clear">Clear sort</button>
  </div>
  <div id="grid" style="height: 340px"></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('oldestFirst').addEventListener('click', () => actions.oldestFirst(api));
document.getElementById('newestFirst').addEventListener('click', () => actions.newestFirst(api));
document.getElementById('shippedAsc').addEventListener('click', () => actions.shippedAsc(api));
document.getElementById('shippedDesc').addEventListener('click', () => actions.shippedDesc(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));
example.js
const text = (value) => value instanceof Date
  ? `${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}`
  : '';
// Date columns compare by calendar date. The time of day is ignored, so orders on the same day keep their original order,
// and rows with an empty shipped date always stay at the end, ascending or descending.
export const options = {
  columns: [
    { id: 'order', title: 'Order No.', width: 120 },
    {
      id: 'ordered',
      title: 'Ordered (with time)',
      kind: 'date',
      width: 190,
      formatValue: (value) => value instanceof Date
        ? `${text(value)} ${String(value.getHours()).padStart(2, '0')}:${String(value.getMinutes()).padStart(2, '0')}`
        : '',
    },
    {
      id: 'shipped',
      title: 'Shipped',
      kind: 'date',
      width: 130,
      formatValue: (value) => text(value),
    },
  ],
  rows: [
    {
      id: 1,
      order: 'SO-1001',
      ordered: new Date(2026, 2, 5, 23, 40),
      shipped: new Date(2026, 2, 7),
    },
    { id: 2, order: 'SO-1002', ordered: new Date(2026, 2, 5, 8, 10), shipped: null },
    {
      id: 3,
      order: 'SO-1003',
      ordered: new Date(2026, 0, 28, 14, 0),
      shipped: new Date(2026, 1, 2),
    },
    {
      id: 4,
      order: 'SO-1004',
      ordered: new Date(2026, 1, 14, 9, 30),
      shipped: new Date(2026, 1, 16),
    },
    {
      id: 5,
      order: 'SO-1005',
      ordered: new Date(2025, 11, 30, 18, 5),
      shipped: new Date(2026, 0, 3),
    },
    { id: 6, order: 'SO-1006', ordered: new Date(2026, 3, 1, 11, 45), shipped: null },
    {
      id: 7,
      order: 'SO-1007',
      ordered: new Date(2026, 2, 19, 16, 20),
      shipped: new Date(2026, 2, 21),
    },
  ],
  rowKey: 'id',
};
export const actions = {
  oldestFirst: (api) => api.setSortModel([{ columnId: 'ordered', direction: 'asc' }]),
  newestFirst: (api) => api.setSortModel([{ columnId: 'ordered', direction: 'desc' }]),
  shippedAsc: (api) => api.setSortModel([{ columnId: 'shipped', direction: 'asc' }]),
  shippedDesc: (api) => api.setSortModel([{ columnId: 'shipped', direction: 'desc' }]),
  clear: (api) => api.setSortModel([]),
};