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

빈 본문 클릭 이벤트Empty body click events

행 아래·옆의 빈 영역을 누르면 bodyClicked·bodyDoubleClicked가 그리드 안쪽 좌표와 함께 와요. 행·머리글·요약·페이저·팝업은 보내지 않아요.Clicking the empty area below or beside the rows sends bodyClicked and bodyDoubleClicked with grid-local coordinates. Rows, headers, summary rows, the pager and popups do not send them.

입문Beginner
직접 써 보기Live preview빈 본문 클릭 이벤트Empty body click events

코드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="selectAll">모두 선택</button>
  </div>
  <div id="grid" style="height: 200px"></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('selectAll').addEventListener('click', () => actions.selectAll(api));
example.js
const en = document.documentElement.dataset.lang === 'en';
export const options = {
  columns: [
    { id: 'name', title: en ? 'Name' : '이름', width: 160 },
    { id: 'team', title: en ? 'Team' : '팀', width: 140 },
  ],
  rows: [
    { id: 1, name: en ? 'Minjun Kim' : '김민준', team: en ? 'Sales' : '영업' },
    { id: 2, name: en ? 'Seoyeon Lee' : '이서연', team: en ? 'Dev' : '개발' },
    { id: 3, name: en ? 'Jiho Park' : '박지호', team: en ? 'Design' : '디자인' },
  ],
  rowKey: 'id',
  selection: 'multiple',
  ariaLabel: en ? 'Click on empty body' : '빈 본문 클릭',
};
// 행 아래의 빈 영역을 누르면 bodyClicked(한 번)·bodyDoubleClicked(두 번)가 그리드 안쪽 좌표 { x, y }와 함께 와요.
// 행·머리글·요약·페이저·팝업을 눌렀을 때는 오지 않아요. 여기서는 빈 곳을 누르면 선택을 풀어요.
export function setup(api, log) {
  log({
    ko: '행 아래 빈 영역을 한 번, 두 번 눌러 보세요. 행을 누르면 rowClicked만 와요.',
    en: 'Click once and twice in the empty area below the rows. Clicking a row sends only rowClicked.',
  });
  const offs = [
    api.on('bodyClicked', (e) => {
      api.setSelectedKeys([]);
      log({
        ko: `빈 곳 클릭 (${Math.round(e.x)}, ${Math.round(e.y)}) → 선택을 풀었어요`,
        en: `Empty area click (${Math.round(e.x)}, ${Math.round(e.y)}) → selection cleared`,
      });
    }),
    api.on('bodyDoubleClicked', (e) => log({
      ko: `빈 곳 더블클릭 (${Math.round(e.x)}, ${Math.round(e.y)})`,
      en: `Empty area double click (${Math.round(e.x)}, ${Math.round(e.y)})`,
    })),
    api.on('rowClicked', (e) => log({ ko: `행 클릭: ${e.rowKey}번`, en: `Row click: ${e.rowKey}` })),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  selectAll: (api) => api.setSelectedKeys([1, 2, 3]),
};

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="selectAll">Select all</button>
  </div>
  <div id="grid" style="height: 200px"></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('selectAll').addEventListener('click', () => actions.selectAll(api));
example.js
export const options = {
  columns: [
    { id: 'name', title: 'Name', width: 160 },
    { id: 'team', title: 'Team', width: 140 },
  ],
  rows: [
    { id: 1, name: 'Liam Carter', team: 'Sales' },
    { id: 2, name: 'Emma Stone', team: 'Dev' },
    { id: 3, name: 'Noah Parker', team: 'Design' },
  ],
  rowKey: 'id',
  selection: 'multiple',
  ariaLabel: 'Click on empty body',
};
// Clicking the empty area below the rows sends bodyClicked (once) or bodyDoubleClicked (twice) with the grid-local { x, y }.
// Clicking a row, header, summary, pager or popup does not send them. Here an empty-area click clears the selection.
export function setup(api, log) {
  log('Click once and twice in the empty area below the rows. Clicking a row sends only rowClicked.');
  const offs = [
    api.on('bodyClicked', (e) => {
      api.setSelectedKeys([]);
      log(`Empty area click (${Math.round(e.x)}, ${Math.round(e.y)}) → selection cleared`);
    }),
    api.on('bodyDoubleClicked', (e) => log(`Empty area double click (${Math.round(e.x)}, ${Math.round(e.y)})`)),
    api.on('rowClicked', (e) => log(`Row click: ${e.rowKey}`)),
  ];
  return () => offs.forEach((off) => off());
}
export const actions = {
  selectAll: (api) => api.setSelectedKeys([1, 2, 3]),
};