날짜 정렬: 시각은 무시, 빈 값은 맨 뒤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.
코드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="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>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));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([]),
};<!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">
<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>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const text = (value) => value instanceof Date
? `${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}`
: '';
// 날짜 컬럼은 달력 날짜로 비교해요. 시각은 무시해서 같은 날 주문은 원래 순서를 지키고,
// 배송일이 비어 있는 행은 오름차순이든 내림차순이든 항상 맨 뒤에 있어요.
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',
};
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([]),
};
options.ariaLabel = "날짜 정렬: 시각은 무시, 빈 값은 맨 뒤";
const api = MaxGrid.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));
</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.oldestFirst(api)}
>주문일 빠른 순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.newestFirst(api)}
>주문일 늦은 순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shippedAsc(api)}
>배송일 오름차순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shippedDesc(api)}
>배송일 내림차순</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>정렬 해제</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
order: string;
ordered: Date;
shipped: Date | null;
}
const text = (value: unknown): string =>
value instanceof Date
? `${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}`
: '';
// 날짜 컬럼은 달력 날짜로 비교해요. 시각은 무시해서 같은 날 주문은 원래 순서를 지키고,
// 배송일이 비어 있는 행은 오름차순이든 내림차순이든 항상 맨 뒤에 있어요.
export const options: GridOptions<Row> = {
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: GridApi<Row>) => api.setSortModel([{ columnId: 'ordered', direction: 'asc' }]),
newestFirst: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'ordered', direction: 'desc' }]),
shippedAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'shipped', direction: 'asc' }]),
shippedDesc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'shipped', 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.oldestFirst(api)"
>주문일 빠른 순</button>
<button
type="button"
:disabled="!api"
@click="api && actions.newestFirst(api)"
>주문일 늦은 순</button>
<button
type="button"
:disabled="!api"
@click="api && actions.shippedAsc(api)"
>배송일 오름차순</button>
<button
type="button"
:disabled="!api"
@click="api && actions.shippedDesc(api)"
>배송일 내림차순</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">정렬 해제</button>
</div>
<Grid style="height: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
order: string;
ordered: Date;
shipped: Date | null;
}
const text = (value: unknown): string =>
value instanceof Date
? `${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}`
: '';
// 날짜 컬럼은 달력 날짜로 비교해요. 시각은 무시해서 같은 날 주문은 원래 순서를 지키고,
// 배송일이 비어 있는 행은 오름차순이든 내림차순이든 항상 맨 뒤에 있어요.
export const options: GridOptions<Row> = {
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: GridApi<Row>) => api.setSortModel([{ columnId: 'ordered', direction: 'asc' }]),
newestFirst: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'ordered', direction: 'desc' }]),
shippedAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'shipped', direction: 'asc' }]),
shippedDesc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'shipped', 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.oldestFirst(api)"
>주문일 빠른 순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.newestFirst(api)"
>주문일 늦은 순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shippedAsc(api)"
>배송일 오름차순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shippedDesc(api)"
>배송일 내림차순</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>정렬 해제</button>
</div>
<mx-grid style="height: 340px" [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;
order: string;
ordered: Date;
shipped: Date | null;
}
const text = (value: unknown): string =>
value instanceof Date
? `${value.getFullYear()}-${String(value.getMonth() + 1).padStart(2, '0')}-${String(value.getDate()).padStart(2, '0')}`
: '';
// 날짜 컬럼은 달력 날짜로 비교해요. 시각은 무시해서 같은 날 주문은 원래 순서를 지키고,
// 배송일이 비어 있는 행은 오름차순이든 내림차순이든 항상 맨 뒤에 있어요.
export const options: GridOptions<Row> = {
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: GridApi<Row>) => api.setSortModel([{ columnId: 'ordered', direction: 'asc' }]),
newestFirst: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'ordered', direction: 'desc' }]),
shippedAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'shipped', direction: 'asc' }]),
shippedDesc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'shipped', 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="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>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));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([]),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Date sorting: ignore time, empty values last</title>
</head>
<body>
<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>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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.
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',
};
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([]),
};
options.ariaLabel = "Date sorting: ignore time, empty values last";
const api = MaxGrid.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));
</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.oldestFirst(api)}
>Oldest order first</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.newestFirst(api)}
>Newest order first</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shippedAsc(api)}
>Shipped ascending</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.shippedDesc(api)}
>Shipped descending</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear sort</button>
</div>
<Grid style={{ height: 340 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export interface Row {
id: number;
order: string;
ordered: Date;
shipped: Date | null;
}
const text = (value: unknown): string =>
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: GridOptions<Row> = {
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: GridApi<Row>) => api.setSortModel([{ columnId: 'ordered', direction: 'asc' }]),
newestFirst: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'ordered', direction: 'desc' }]),
shippedAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'shipped', direction: 'asc' }]),
shippedDesc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'shipped', 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.oldestFirst(api)"
>Oldest order first</button>
<button
type="button"
:disabled="!api"
@click="api && actions.newestFirst(api)"
>Newest order first</button>
<button
type="button"
:disabled="!api"
@click="api && actions.shippedAsc(api)"
>Shipped ascending</button>
<button
type="button"
:disabled="!api"
@click="api && actions.shippedDesc(api)"
>Shipped descending</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear sort</button>
</div>
<Grid style="height: 340px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export interface Row {
id: number;
order: string;
ordered: Date;
shipped: Date | null;
}
const text = (value: unknown): string =>
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: GridOptions<Row> = {
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: GridApi<Row>) => api.setSortModel([{ columnId: 'ordered', direction: 'asc' }]),
newestFirst: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'ordered', direction: 'desc' }]),
shippedAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'shipped', direction: 'asc' }]),
shippedDesc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'shipped', 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.oldestFirst(api)"
>Oldest order first</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.newestFirst(api)"
>Newest order first</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shippedAsc(api)"
>Shipped ascending</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.shippedDesc(api)"
>Shipped descending</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear sort</button>
</div>
<mx-grid style="height: 340px" [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;
order: string;
ordered: Date;
shipped: Date | null;
}
const text = (value: unknown): string =>
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: GridOptions<Row> = {
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: GridApi<Row>) => api.setSortModel([{ columnId: 'ordered', direction: 'asc' }]),
newestFirst: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'ordered', direction: 'desc' }]),
shippedAsc: (api: GridApi<Row>) => api.setSortModel([{ columnId: 'shipped', direction: 'asc' }]),
shippedDesc: (api: GridApi<Row>) =>
api.setSortModel([{ columnId: 'shipped', direction: 'desc' }]),
clear: (api: GridApi<Row>) => api.setSortModel([]),
};