안내를 직접 그리기Draw the notice yourself
overlays.noRows에 함수를 주면 안내 요소(host)에 원하는 모양을 직접 그려요. 정리 함수를 돌려주면 안내가 사라질 때 한 번 불러요.Give overlays.noRows a function and draw anything into the notice element (host). A returned cleanup function is called once when the notice goes away.
코드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="empty">비우기</button>
<button type="button" id="fill">채우기</button>
</div>
<div id="grid" style="height: 260px"></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('empty').addEventListener('click', () => actions.empty(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));const sample = [
{ id: 1, task: '견적서 보내기' },
{ id: 2, task: '계약서 검토' },
];
let say = () => undefined;
let fillRows = null;
// 함수 명세는 안내 요소(host)에 직접 그려요. 돌려주는 함수는 안내가 사라질 때 한 번 불려요.
export const options = {
columns: [{ id: 'task', title: '작업', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = '아직 작업이 없어요.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = '예제 행 추가';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say({ ko: '직접 그린 안내를 정리했어요.', en: 'Cleaned up the custom notice.' });
},
},
};
export function setup(grid, log) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
export const actions = {
empty: (grid) => grid.setRows([]),
fill: (grid) => grid.setRows(sample),
};<!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="empty">비우기</button>
<button type="button" id="fill">채우기</button>
</div>
<div id="grid" style="height: 260px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const sample = [
{ id: 1, task: '견적서 보내기' },
{ id: 2, task: '계약서 검토' },
];
let say = () => undefined;
let fillRows = null;
// 함수 명세는 안내 요소(host)에 직접 그려요. 돌려주는 함수는 안내가 사라질 때 한 번 불려요.
const options = {
columns: [{ id: 'task', title: '작업', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = '아직 작업이 없어요.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = '예제 행 추가';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say({ ko: '직접 그린 안내를 정리했어요.', en: 'Cleaned up the custom notice.' });
},
},
};
function setup(grid, log) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
const actions = {
empty: (grid) => grid.setRows([]),
fill: (grid) => grid.setRows(sample),
};
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('empty').addEventListener('click', () => actions.empty(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.empty(api)}
>비우기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.fill(api)}
>채우기</button>
</div>
<Grid style={{ height: 260 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
task: string;
}
const sample: Row[] = [
{ id: 1, task: '견적서 보내기' },
{ id: 2, task: '계약서 검토' },
];
let say: (message: LogText) => void = () => undefined;
let fillRows: (() => void) | null = null;
// 함수 명세는 안내 요소(host)에 직접 그려요. 돌려주는 함수는 안내가 사라질 때 한 번 불려요.
export const options: GridOptions<Row> = {
columns: [{ id: 'task', title: '작업', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = '아직 작업이 없어요.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = '예제 행 추가';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say({ ko: '직접 그린 안내를 정리했어요.', en: 'Cleaned up the custom notice.' });
},
},
};
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
export const actions = {
empty: (grid: GridApi<Row>) => grid.setRows([]),
fill: (grid: GridApi<Row>) => grid.setRows(sample),
};버튼을 누르면 이 예제의 코드가 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">
<button type="button" :disabled="!api" @click="api && actions.empty(api)">비우기</button>
<button type="button" :disabled="!api" @click="api && actions.fill(api)">채우기</button>
</div>
<Grid style="height: 260px" :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;
task: string;
}
const sample: Row[] = [
{ id: 1, task: '견적서 보내기' },
{ id: 2, task: '계약서 검토' },
];
let say: (message: LogText) => void = () => undefined;
let fillRows: (() => void) | null = null;
// 함수 명세는 안내 요소(host)에 직접 그려요. 돌려주는 함수는 안내가 사라질 때 한 번 불려요.
export const options: GridOptions<Row> = {
columns: [{ id: 'task', title: '작업', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = '아직 작업이 없어요.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = '예제 행 추가';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say({ ko: '직접 그린 안내를 정리했어요.', en: 'Cleaned up the custom notice.' });
},
},
};
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
export const actions = {
empty: (grid: GridApi<Row>) => grid.setRows([]),
fill: (grid: GridApi<Row>) => grid.setRows(sample),
};버튼을 누르면 이 예제의 코드가 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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.empty(api)"
>비우기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.fill(api)"
>채우기</button>
</div>
<mx-grid style="height: 260px" [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;
task: string;
}
const sample: Row[] = [
{ id: 1, task: '견적서 보내기' },
{ id: 2, task: '계약서 검토' },
];
let say: (message: LogText) => void = () => undefined;
let fillRows: (() => void) | null = null;
// 함수 명세는 안내 요소(host)에 직접 그려요. 돌려주는 함수는 안내가 사라질 때 한 번 불려요.
export const options: GridOptions<Row> = {
columns: [{ id: 'task', title: '작업', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = '아직 작업이 없어요.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = '예제 행 추가';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say({ ko: '직접 그린 안내를 정리했어요.', en: 'Cleaned up the custom notice.' });
},
},
};
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
export const actions = {
empty: (grid: GridApi<Row>) => grid.setRows([]),
fill: (grid: GridApi<Row>) => grid.setRows(sample),
};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="empty">Empty</button>
<button type="button" id="fill">Fill</button>
</div>
<div id="grid" style="height: 260px"></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('empty').addEventListener('click', () => actions.empty(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(api));const sample = [
{ id: 1, task: 'Send the quote' },
{ id: 2, task: 'Review the contract' },
];
let say = () => undefined;
let fillRows = null;
// A function spec draws directly into the notice element (host). The returned function is called once when the notice goes away.
export const options = {
columns: [{ id: 'task', title: 'Task', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = 'There are no tasks yet.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = 'Add example rows';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say('Cleaned up the custom notice.');
},
},
};
export function setup(grid, log) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
export const actions = {
empty: (grid) => grid.setRows([]),
fill: (grid) => grid.setRows(sample),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Draw the notice yourself</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="empty">Empty</button>
<button type="button" id="fill">Fill</button>
</div>
<div id="grid" style="height: 260px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const sample = [
{ id: 1, task: 'Send the quote' },
{ id: 2, task: 'Review the contract' },
];
let say = () => undefined;
let fillRows = null;
// A function spec draws directly into the notice element (host). The returned function is called once when the notice goes away.
const options = {
columns: [{ id: 'task', title: 'Task', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = 'There are no tasks yet.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = 'Add example rows';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say('Cleaned up the custom notice.');
},
},
};
function setup(grid, log) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
const actions = {
empty: (grid) => grid.setRows([]),
fill: (grid) => grid.setRows(sample),
};
options.ariaLabel = "Draw the notice yourself";
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('empty').addEventListener('click', () => actions.empty(api));
document.getElementById('fill').addEventListener('click', () => actions.fill(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.empty(api)}
>Empty</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.fill(api)}
>Fill</button>
</div>
<Grid style={{ height: 260 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
task: string;
}
const sample: Row[] = [
{ id: 1, task: 'Send the quote' },
{ id: 2, task: 'Review the contract' },
];
let say: (message: LogText) => void = () => undefined;
let fillRows: (() => void) | null = null;
// A function spec draws directly into the notice element (host). The returned function is called once when the notice goes away.
export const options: GridOptions<Row> = {
columns: [{ id: 'task', title: 'Task', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = 'There are no tasks yet.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = 'Add example rows';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say('Cleaned up the custom notice.');
},
},
};
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
export const actions = {
empty: (grid: GridApi<Row>) => grid.setRows([]),
fill: (grid: GridApi<Row>) => grid.setRows(sample),
};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">
<button type="button" :disabled="!api" @click="api && actions.empty(api)">Empty</button>
<button type="button" :disabled="!api" @click="api && actions.fill(api)">Fill</button>
</div>
<Grid style="height: 260px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
task: string;
}
const sample: Row[] = [
{ id: 1, task: 'Send the quote' },
{ id: 2, task: 'Review the contract' },
];
let say: (message: LogText) => void = () => undefined;
let fillRows: (() => void) | null = null;
// A function spec draws directly into the notice element (host). The returned function is called once when the notice goes away.
export const options: GridOptions<Row> = {
columns: [{ id: 'task', title: 'Task', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = 'There are no tasks yet.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = 'Add example rows';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say('Cleaned up the custom notice.');
},
},
};
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
export const actions = {
empty: (grid: GridApi<Row>) => grid.setRows([]),
fill: (grid: GridApi<Row>) => grid.setRows(sample),
};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">
<button
type="button"
[disabled]="!api"
(click)="api && actions.empty(api)"
>Empty</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.fill(api)"
>Fill</button>
</div>
<mx-grid style="height: 260px" [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;
task: string;
}
const sample: Row[] = [
{ id: 1, task: 'Send the quote' },
{ id: 2, task: 'Review the contract' },
];
let say: (message: LogText) => void = () => undefined;
let fillRows: (() => void) | null = null;
// A function spec draws directly into the notice element (host). The returned function is called once when the notice goes away.
export const options: GridOptions<Row> = {
columns: [{ id: 'task', title: 'Task', width: 220 }],
rows: [],
rowKey: 'id',
overlays: {
noRows: (host) => {
const message = document.createElement('div');
message.textContent = 'There are no tasks yet.';
const add = document.createElement('button');
add.type = 'button';
add.textContent = 'Add example rows';
add.addEventListener('click', () => fillRows?.());
host.append(message, add);
return () => say('Cleaned up the custom notice.');
},
},
};
export function setup(grid: GridApi<Row>, log: (message: LogText) => void) {
say = log;
fillRows = () => grid.setRows(sample);
return () => {
fillRows = null;
};
}
export const actions = {
empty: (grid: GridApi<Row>) => grid.setRows([]),
fill: (grid: GridApi<Row>) => grid.setRows(sample),
};