안내를 코드로 켜고 끄기Show and hide a notice from code
api.showOverlay로 행 수와 상관없이 안내를 보이고 api.hideOverlay로 자동 판단으로 돌아가요. 점검 중 같은 문구를 글자로 바로 줄 수도 있어요.api.showOverlay shows a notice regardless of the row count and api.hideOverlay returns to automatic. You can also pass a plain text such as a maintenance message.
코드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="loading">로딩 보이기</button>
<button type="button" id="maintenance">점검 중 보이기</button>
<button type="button" id="hide">숨기기</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('loading').addEventListener('click', () => actions.loading(api));
document.getElementById('maintenance').addEventListener('click', () => actions.maintenance(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));// showOverlay는 행 수와 상관없이 안내를 지금 보이는 본문 위에 덮고, hideOverlay로 자동 판단으로 돌아가요.
export const options = {
columns: [{ id: 'name', title: '이름', width: 160 }],
rows: [
{ id: 1, name: '김서연' },
{ id: 2, name: '이준호' },
{ id: 3, name: '박민지' },
],
rowKey: 'id',
};
export function setup(_grid, log) {
log({
ko: '버튼으로 안내를 켜고 꺼 보세요.',
en: 'Use the buttons to turn a notice on and off.',
});
}
export const actions = {
loading: (grid) => grid.showOverlay('loading'),
maintenance: (grid) => grid.showOverlay('점검 중이에요. 잠시 뒤에 다시 시도해 주세요.'),
hide: (grid) => grid.hideOverlay(),
};<!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="loading">로딩 보이기</button>
<button type="button" id="maintenance">점검 중 보이기</button>
<button type="button" id="hide">숨기기</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>
// showOverlay는 행 수와 상관없이 안내를 지금 보이는 본문 위에 덮고, hideOverlay로 자동 판단으로 돌아가요.
const options = {
columns: [{ id: 'name', title: '이름', width: 160 }],
rows: [
{ id: 1, name: '김서연' },
{ id: 2, name: '이준호' },
{ id: 3, name: '박민지' },
],
rowKey: 'id',
};
function setup(_grid, log) {
log({
ko: '버튼으로 안내를 켜고 꺼 보세요.',
en: 'Use the buttons to turn a notice on and off.',
});
}
const actions = {
loading: (grid) => grid.showOverlay('loading'),
maintenance: (grid) => grid.showOverlay('점검 중이에요. 잠시 뒤에 다시 시도해 주세요.'),
hide: (grid) => grid.hideOverlay(),
};
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('loading').addEventListener('click', () => actions.loading(api));
document.getElementById('maintenance').addEventListener('click', () => actions.maintenance(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(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.loading(api)}
>로딩 보이기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.maintenance(api)}
>점검 중 보이기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hide(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;
name: string;
}
// showOverlay는 행 수와 상관없이 안내를 지금 보이는 본문 위에 덮고, hideOverlay로 자동 판단으로 돌아가요.
export const options: GridOptions<Row> = {
columns: [{ id: 'name', title: '이름', width: 160 }],
rows: [
{ id: 1, name: '김서연' },
{ id: 2, name: '이준호' },
{ id: 3, name: '박민지' },
],
rowKey: 'id',
};
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '버튼으로 안내를 켜고 꺼 보세요.',
en: 'Use the buttons to turn a notice on and off.',
});
}
export const actions = {
loading: (grid: GridApi<Row>) => grid.showOverlay('loading'),
maintenance: (grid: GridApi<Row>) =>
grid.showOverlay('점검 중이에요. 잠시 뒤에 다시 시도해 주세요.'),
hide: (grid: GridApi<Row>) => grid.hideOverlay(),
};버튼을 누르면 이 예제의 코드가 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.loading(api)">로딩 보이기</button>
<button
type="button"
:disabled="!api"
@click="api && actions.maintenance(api)"
>점검 중 보이기</button>
<button type="button" :disabled="!api" @click="api && actions.hide(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;
name: string;
}
// showOverlay는 행 수와 상관없이 안내를 지금 보이는 본문 위에 덮고, hideOverlay로 자동 판단으로 돌아가요.
export const options: GridOptions<Row> = {
columns: [{ id: 'name', title: '이름', width: 160 }],
rows: [
{ id: 1, name: '김서연' },
{ id: 2, name: '이준호' },
{ id: 3, name: '박민지' },
],
rowKey: 'id',
};
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '버튼으로 안내를 켜고 꺼 보세요.',
en: 'Use the buttons to turn a notice on and off.',
});
}
export const actions = {
loading: (grid: GridApi<Row>) => grid.showOverlay('loading'),
maintenance: (grid: GridApi<Row>) =>
grid.showOverlay('점검 중이에요. 잠시 뒤에 다시 시도해 주세요.'),
hide: (grid: GridApi<Row>) => grid.hideOverlay(),
};버튼을 누르면 이 예제의 코드가 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.loading(api)"
>로딩 보이기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.maintenance(api)"
>점검 중 보이기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hide(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;
name: string;
}
// showOverlay는 행 수와 상관없이 안내를 지금 보이는 본문 위에 덮고, hideOverlay로 자동 판단으로 돌아가요.
export const options: GridOptions<Row> = {
columns: [{ id: 'name', title: '이름', width: 160 }],
rows: [
{ id: 1, name: '김서연' },
{ id: 2, name: '이준호' },
{ id: 3, name: '박민지' },
],
rowKey: 'id',
};
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '버튼으로 안내를 켜고 꺼 보세요.',
en: 'Use the buttons to turn a notice on and off.',
});
}
export const actions = {
loading: (grid: GridApi<Row>) => grid.showOverlay('loading'),
maintenance: (grid: GridApi<Row>) =>
grid.showOverlay('점검 중이에요. 잠시 뒤에 다시 시도해 주세요.'),
hide: (grid: GridApi<Row>) => grid.hideOverlay(),
};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="loading">Show loading</button>
<button type="button" id="maintenance">Show maintenance</button>
<button type="button" id="hide">Hide</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('loading').addEventListener('click', () => actions.loading(api));
document.getElementById('maintenance').addEventListener('click', () => actions.maintenance(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(api));// showOverlay covers the currently visible body with a notice regardless of the row count, and hideOverlay returns to the automatic decision.
export const options = {
columns: [{ id: 'name', title: 'Name', width: 160 }],
rows: [
{ id: 1, name: 'Emma Stone' },
{ id: 2, name: 'Liam Carter' },
{ id: 3, name: 'Olivia Hayes' },
],
rowKey: 'id',
};
export function setup(_grid, log) {
log('Use the buttons to turn a notice on and off.');
}
export const actions = {
loading: (grid) => grid.showOverlay('loading'),
maintenance: (grid) => grid.showOverlay('Under maintenance. Please try again in a moment.'),
hide: (grid) => grid.hideOverlay(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Show and hide a notice from code</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="loading">Show loading</button>
<button type="button" id="maintenance">Show maintenance</button>
<button type="button" id="hide">Hide</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>
// showOverlay covers the currently visible body with a notice regardless of the row count, and hideOverlay returns to the automatic decision.
const options = {
columns: [{ id: 'name', title: 'Name', width: 160 }],
rows: [
{ id: 1, name: 'Emma Stone' },
{ id: 2, name: 'Liam Carter' },
{ id: 3, name: 'Olivia Hayes' },
],
rowKey: 'id',
};
function setup(_grid, log) {
log('Use the buttons to turn a notice on and off.');
}
const actions = {
loading: (grid) => grid.showOverlay('loading'),
maintenance: (grid) => grid.showOverlay('Under maintenance. Please try again in a moment.'),
hide: (grid) => grid.hideOverlay(),
};
options.ariaLabel = "Show and hide a notice from code";
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('loading').addEventListener('click', () => actions.loading(api));
document.getElementById('maintenance').addEventListener('click', () => actions.maintenance(api));
document.getElementById('hide').addEventListener('click', () => actions.hide(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.loading(api)}
>Show loading</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.maintenance(api)}
>Show maintenance</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.hide(api)}
>Hide</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;
name: string;
}
// showOverlay covers the currently visible body with a notice regardless of the row count, and hideOverlay returns to the automatic decision.
export const options: GridOptions<Row> = {
columns: [{ id: 'name', title: 'Name', width: 160 }],
rows: [
{ id: 1, name: 'Emma Stone' },
{ id: 2, name: 'Liam Carter' },
{ id: 3, name: 'Olivia Hayes' },
],
rowKey: 'id',
};
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
log('Use the buttons to turn a notice on and off.');
}
export const actions = {
loading: (grid: GridApi<Row>) => grid.showOverlay('loading'),
maintenance: (grid: GridApi<Row>) =>
grid.showOverlay('Under maintenance. Please try again in a moment.'),
hide: (grid: GridApi<Row>) => grid.hideOverlay(),
};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.loading(api)">Show loading</button>
<button
type="button"
:disabled="!api"
@click="api && actions.maintenance(api)"
>Show maintenance</button>
<button type="button" :disabled="!api" @click="api && actions.hide(api)">Hide</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;
name: string;
}
// showOverlay covers the currently visible body with a notice regardless of the row count, and hideOverlay returns to the automatic decision.
export const options: GridOptions<Row> = {
columns: [{ id: 'name', title: 'Name', width: 160 }],
rows: [
{ id: 1, name: 'Emma Stone' },
{ id: 2, name: 'Liam Carter' },
{ id: 3, name: 'Olivia Hayes' },
],
rowKey: 'id',
};
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
log('Use the buttons to turn a notice on and off.');
}
export const actions = {
loading: (grid: GridApi<Row>) => grid.showOverlay('loading'),
maintenance: (grid: GridApi<Row>) =>
grid.showOverlay('Under maintenance. Please try again in a moment.'),
hide: (grid: GridApi<Row>) => grid.hideOverlay(),
};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.loading(api)"
>Show loading</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.maintenance(api)"
>Show maintenance</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.hide(api)"
>Hide</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;
name: string;
}
// showOverlay covers the currently visible body with a notice regardless of the row count, and hideOverlay returns to the automatic decision.
export const options: GridOptions<Row> = {
columns: [{ id: 'name', title: 'Name', width: 160 }],
rows: [
{ id: 1, name: 'Emma Stone' },
{ id: 2, name: 'Liam Carter' },
{ id: 3, name: 'Olivia Hayes' },
],
rowKey: 'id',
};
export function setup(_grid: GridApi<Row>, log: (message: LogText) => void) {
log('Use the buttons to turn a notice on and off.');
}
export const actions = {
loading: (grid: GridApi<Row>) => grid.showOverlay('loading'),
maintenance: (grid: GridApi<Row>) =>
grid.showOverlay('Under maintenance. Please try again in a moment.'),
hide: (grid: GridApi<Row>) => grid.hideOverlay(),
};