빈 본문 클릭 이벤트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.
코드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="selectAll">모두 선택</button>
</div>
<div id="grid" style="height: 200px"></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('selectAll').addEventListener('click', () => actions.selectAll(api));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]),
};<!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="selectAll">모두 선택</button>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const en = document.documentElement.dataset.lang === 'en';
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 }와 함께 와요.
// 행·머리글·요약·페이저·팝업을 눌렀을 때는 오지 않아요. 여기서는 빈 곳을 누르면 선택을 풀어요.
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());
}
const actions = {
selectAll: (api) => api.setSelectedKeys([1, 2, 3]),
};
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('selectAll').addEventListener('click', () => actions.selectAll(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.selectAll(api)}
>모두 선택</button>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
}
export const options: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.setSelectedKeys([1, 2, 3]),
};버튼을 누르면 이 예제의 코드가 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.selectAll(api)"
>모두 선택</button>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
}
export const options: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.setSelectedKeys([1, 2, 3]),
};버튼을 누르면 이 예제의 코드가 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.selectAll(api)"
>모두 선택</button>
</div>
<mx-grid style="height: 200px" [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';
const en = document.documentElement.dataset.lang === 'en';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
}
export const options: GridOptions<Row> = {
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: GridApi<Row>, log: (message: LogText) => void) {
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: GridApi<Row>) => api.setSelectedKeys([1, 2, 3]),
};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="selectAll">Select all</button>
</div>
<div id="grid" style="height: 200px"></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('selectAll').addEventListener('click', () => actions.selectAll(api));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]),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Empty body click events</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="selectAll">Select all</button>
</div>
<div id="grid" style="height: 200px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
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.
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());
}
const actions = {
selectAll: (api) => api.setSelectedKeys([1, 2, 3]),
};
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('selectAll').addEventListener('click', () => actions.selectAll(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.selectAll(api)}
>Select all</button>
</div>
<Grid style={{ height: 200 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
}
export const options: GridOptions<Row> = {
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: GridApi<Row>, log: (message: string) => void) {
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: GridApi<Row>) => api.setSelectedKeys([1, 2, 3]),
};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.selectAll(api)"
>Select all</button>
</div>
<Grid style="height: 200px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
}
export const options: GridOptions<Row> = {
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: GridApi<Row>, log: (message: string) => void) {
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: GridApi<Row>) => api.setSelectedKeys([1, 2, 3]),
};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.selectAll(api)"
>Select all</button>
</div>
<mx-grid style="height: 200px" [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;
team: string;
}
export const options: GridOptions<Row> = {
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: GridApi<Row>, log: (message: string) => void) {
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: GridApi<Row>) => api.setSelectedKeys([1, 2, 3]),
};