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

안내를 직접 그리기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.

활용Intermediate
직접 써 보기Live preview안내를 직접 그리기Draw the notice yourself

코드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="empty">비우기</button>
    <button type="button" id="fill">채우기</button>
  </div>
  <div id="grid" style="height: 260px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
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));
example.js
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),
};

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="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>
main.js
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));
example.js
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),
};