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

빈 목록·불러오는 중 안내 문구 바꾸기Change the empty and loading messages

결과가 없을 때와 불러오는 중에 보이는 안내 문구는 언어에 따라 기본 문구가 달라지고, 원하는 말로 직접 바꿔 쓸 수도 있어요. 필터로 가려진 경우와 데이터가 아예 없는 경우 모두 같은 빈 목록 문구가 나와요.The texts for an empty result and for loading follow the language, and you can replace each with your own wording. The same empty text shows whether a filter hides every row or there is no data at all.

입문Beginner
직접 써 보기Live preview빈 목록·불러오는 중 안내 문구 바꾸기Change the empty and loading messages

코드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="noMatch">일치하는 행 없음</button>
    <button type="button" id="noData">데이터 비우기</button>
    <button type="button" id="loading">불러오는 중 보기</button>
    <button type="button" id="restore">원래대로</button>
    <select aria-label="언어" id="locale">
      <option value="ko" selected>한국어 (기본)</option>
      <option value="en">English</option>
    </select>
    <select aria-label="안내 문구" id="wording">
      <option value="builtin" selected>기본 문구 (기본)</option>
      <option value="custom">내 문구</option>
    </select>
  </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);
document.getElementById('noMatch').addEventListener('click', () => actions.noMatch(api));
document.getElementById('noData').addEventListener('click', () => actions.noData(api));
document.getElementById('loading').addEventListener('click', () => actions.loading(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(api));
document.getElementById('locale').addEventListener('change', (event) => actions.locale(api, event.target.value));
document.getElementById('wording').addEventListener('change', (event) => actions.wording(api, event.target.value));
example.js
// 예제 틀이 알려 주는 페이지 언어(ko/en)에 맞는 문구를 골라요.
const L = (ko, en) => document.documentElement.dataset.lang === 'en' ? en : ko;
const ROWS = [
  { id: 1, name: '김민준', dept: '개발팀' },
  { id: 2, name: '이서연', dept: '디자인팀' },
  { id: 3, name: '박지호', dept: '영업팀' },
  { id: 4, name: '최유나', dept: '개발팀' },
];
// locale은 기본 문구(빈 목록, 불러오는 중)의 언어를 정하고, messages는 그 위에 문구 하나하나를 덮어써요.
const CUSTOM = {
  noRows: L('조건에 맞는 직원이 없어요.', 'No employee matches.'),
  loading: L('직원 목록을 불러오는 중…', 'Loading the employee list…'),
};
export const options = {
  columns: [
    { id: 'name', title: '이름', width: 150 },
    { id: 'dept', title: '부서', width: 150 },
  ],
  rows: ROWS,
  rowKey: 'id',
  locale: 'ko',
};
let timer;
export function setup(_api) {
  return () => clearTimeout(timer);
}
export const actions = {
  // 필터가 모든 행을 가려도 데이터는 그대로 있어요. 필터를 풀면 돌아와요.
  noMatch: (api) => api.setFilterModel({
    match: 'all',
    items: [{ columnId: 'name', operator: 'contains', value: 'zzz' }],
  }),
  // 데이터 자체가 비면 같은 빈 목록 문구가 나와요.
  noData: (api) => api.setRows([]),
  restore: (api) => {
    api.setFilterModel(null);
    api.setRows(ROWS);
  },
  loading: (api) => {
    api.setOptions({ loading: true });
    clearTimeout(timer);
    timer = setTimeout(() => {
      if (!api.isDestroyed())
        api.setOptions({ loading: false });
    }, 1500);
  },
  locale: (api, value) => {
    if (value === 'ko' || value === 'en')
      api.setOptions({ locale: value });
  },
  wording: (api, value) => api.setOptions({ messages: value === 'custom' ? CUSTOM : {} }),
};

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="noMatch">No matching rows</button>
    <button type="button" id="noData">Empty the data</button>
    <button type="button" id="loading">Show loading</button>
    <button type="button" id="restore">Restore</button>
    <select aria-label="Language" id="locale">
      <option value="ko" selected>Korean (default)</option>
      <option value="en">English</option>
    </select>
    <select aria-label="Wording" id="wording">
      <option value="builtin" selected>Built-in (default)</option>
      <option value="custom">Custom</option>
    </select>
  </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);
document.getElementById('noMatch').addEventListener('click', () => actions.noMatch(api));
document.getElementById('noData').addEventListener('click', () => actions.noData(api));
document.getElementById('loading').addEventListener('click', () => actions.loading(api));
document.getElementById('restore').addEventListener('click', () => actions.restore(api));
document.getElementById('locale').addEventListener('change', (event) => actions.locale(api, event.target.value));
document.getElementById('wording').addEventListener('change', (event) => actions.wording(api, event.target.value));
example.js
const ROWS = [
  { id: 1, name: 'Liam Carter', dept: 'Dev' },
  { id: 2, name: 'Emma Stone', dept: 'Design' },
  { id: 3, name: 'Noah Parker', dept: 'Sales' },
  { id: 4, name: 'Olivia Reed', dept: 'Dev' },
];
// locale sets the language of the default messages (empty list, loading), and messages overrides each message on top of it.
const CUSTOM = {
  noRows: 'No employee matches.',
  loading: 'Loading the employee list…',
};
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 150 },
    { id: 'dept', title: 'Dept', width: 150 },
  ],
  rows: ROWS,
  rowKey: 'id',
  locale: 'en',
};
let timer;
export function setup(_api) {
  return () => clearTimeout(timer);
}
export const actions = {
  // Even when the filter hides every row, the data is still there. Clear the filter and the rows come back.
  noMatch: (api) => api.setFilterModel({
    match: 'all',
    items: [{ columnId: 'name', operator: 'contains', value: 'zzz' }],
  }),
  // If the data itself is empty, the same empty-list message appears.
  noData: (api) => api.setRows([]),
  restore: (api) => {
    api.setFilterModel(null);
    api.setRows(ROWS);
  },
  loading: (api) => {
    api.setOptions({ loading: true });
    clearTimeout(timer);
    timer = setTimeout(() => {
      if (!api.isDestroyed())
        api.setOptions({ loading: false });
    }, 1500);
  },
  locale: (api, value) => {
    if (value === 'ko' || value === 'en')
      api.setOptions({ locale: value });
  },
  wording: (api, value) => api.setOptions({ messages: value === 'custom' ? CUSTOM : {} }),
};