행 선택 방식: 단일·여러 개·체크박스Row selection modes: single, multiple, checkbox
행을 하나만 고르게 하거나, 여러 개를 고르게 하거나, 체크박스 열을 붙일 수 있어요. 선택이 바뀔 때마다 고른 행과 합계를 알려 줄 수 있고, 방식은 쓰는 도중에 바꿀 수도 있어요.Let users pick one row, many rows, or many with a checkbox column. Each change can report the chosen rows and a total, and the mode can be switched while running.
코드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">
<select aria-label="선택 방식" id="mode">
<option value="multipleCheck" selected>여러 행 + 체크박스 (기본)</option>
<option value="multiple">여러 행 (체크박스 없음)</option>
<option value="single">한 행만</option>
<option value="none">끔</option>
</select>
<button type="button" id="pickTwo">두 행 고르기</button>
<button type="button" id="clear">선택 지우기</button>
</div>
<div id="grid" style="height: 380px"></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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('pickTwo').addEventListener('click', () => actions.pickTwo(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'바다유통',
'해든전자',
];
const statuses = ['결제 완료', '대기', '연체'];
export const options = {
columns: [
{ id: 'customer', title: '고객사', width: 150 },
{ id: 'status', title: '상태', width: 110 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3],
amount: 430000 + ((i * 613000) % 2900000),
})),
rowKey: 'id',
// 체크박스 열을 둔 여러 행 선택. Shift+클릭은 범위, Ctrl+클릭은 하나씩 켜고 끄기, 포커스된 행에서 Space는 토글이에요.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
};
let say = () => { };
export function setup(api, log) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log({
ko: rows.length === 0
? '선택 없음'
: `${rows.length}행 선택 (${rows.map((r) => r.customer).join(', ')}) · 금액 합계 ${total.toLocaleString('ko-KR')}원`,
en: rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount ${total.toLocaleString('en-US')} KRW`,
});
});
}
export const actions = {
// 방식을 바꾸면 이미 고른 행은 새 방식에 맞게 정리돼요(단일이면 하나만 남고, 끔이면 모두 풀려요).
mode: (api, value) => {
api.setOptions({
selection: MODES[value ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api) => {
try {
api.setSelectedKeys([2, 4]);
}
catch {
say({
ko: '이 방식에서는 두 행을 한꺼번에 고를 수 없어요',
en: 'This mode cannot select two rows at once',
});
}
},
clear: (api) => api.clearSelection(),
};<!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">
<select aria-label="선택 방식" id="mode">
<option value="multipleCheck" selected>여러 행 + 체크박스 (기본)</option>
<option value="multiple">여러 행 (체크박스 없음)</option>
<option value="single">한 행만</option>
<option value="none">끔</option>
</select>
<button type="button" id="pickTwo">두 행 고르기</button>
<button type="button" id="clear">선택 지우기</button>
</div>
<div id="grid" style="height: 380px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'바다유통',
'해든전자',
];
const statuses = ['결제 완료', '대기', '연체'];
const options = {
columns: [
{ id: 'customer', title: '고객사', width: 150 },
{ id: 'status', title: '상태', width: 110 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3],
amount: 430000 + ((i * 613000) % 2900000),
})),
rowKey: 'id',
// 체크박스 열을 둔 여러 행 선택. Shift+클릭은 범위, Ctrl+클릭은 하나씩 켜고 끄기, 포커스된 행에서 Space는 토글이에요.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
};
let say = () => { };
function setup(api, log) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log({
ko: rows.length === 0
? '선택 없음'
: `${rows.length}행 선택 (${rows.map((r) => r.customer).join(', ')}) · 금액 합계 ${total.toLocaleString('ko-KR')}원`,
en: rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount ${total.toLocaleString('en-US')} KRW`,
});
});
}
const actions = {
// 방식을 바꾸면 이미 고른 행은 새 방식에 맞게 정리돼요(단일이면 하나만 남고, 끔이면 모두 풀려요).
mode: (api, value) => {
api.setOptions({
selection: MODES[value ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api) => {
try {
api.setSelectedKeys([2, 4]);
}
catch {
say({
ko: '이 방식에서는 두 행을 한꺼번에 고를 수 없어요',
en: 'This mode cannot select two rows at once',
});
}
},
clear: (api) => api.clearSelection(),
};
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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('pickTwo').addEventListener('click', () => actions.pickTwo(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(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">
<select
aria-label="선택 방식"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="multipleCheck">여러 행 + 체크박스 (기본)</option>
<option value="multiple">여러 행 (체크박스 없음)</option>
<option value="single">한 행만</option>
<option value="none">끔</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.pickTwo(api)}
>두 행 고르기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>선택 지우기</button>
</div>
<Grid style={{ height: 380 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
status: string;
amount: number;
}
const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'바다유통',
'해든전자',
];
const statuses = ['결제 완료', '대기', '연체'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객사', width: 150 },
{ id: 'status', title: '상태', width: 110 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3] as string,
amount: 430000 + ((i * 613000) % 2900000),
})),
rowKey: 'id',
// 체크박스 열을 둔 여러 행 선택. Shift+클릭은 범위, Ctrl+클릭은 하나씩 켜고 끄기, 포커스된 행에서 Space는 토글이에요.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
} as const;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log({
ko:
rows.length === 0
? '선택 없음'
: `${rows.length}행 선택 (${rows.map((r) => r.customer).join(', ')}) · 금액 합계 ${total.toLocaleString('ko-KR')}원`,
en:
rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount ${total.toLocaleString('en-US')} KRW`,
});
});
}
export const actions = {
// 방식을 바꾸면 이미 고른 행은 새 방식에 맞게 정리돼요(단일이면 하나만 남고, 끔이면 모두 풀려요).
mode: (api: GridApi<Row>, value?: string) => {
api.setOptions({
selection: MODES[(value as keyof typeof MODES) ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api: GridApi<Row>) => {
try {
api.setSelectedKeys([2, 4]);
} catch {
say({
ko: '이 방식에서는 두 행을 한꺼번에 고를 수 없어요',
en: 'This mode cannot select two rows at once',
});
}
},
clear: (api: GridApi<Row>) => api.clearSelection(),
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="선택 방식"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="multipleCheck" selected>여러 행 + 체크박스 (기본)</option>
<option value="multiple">여러 행 (체크박스 없음)</option>
<option value="single">한 행만</option>
<option value="none">끔</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.pickTwo(api)">두 행 고르기</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">선택 지우기</button>
</div>
<Grid style="height: 380px" :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;
customer: string;
status: string;
amount: number;
}
const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'바다유통',
'해든전자',
];
const statuses = ['결제 완료', '대기', '연체'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객사', width: 150 },
{ id: 'status', title: '상태', width: 110 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3] as string,
amount: 430000 + ((i * 613000) % 2900000),
})),
rowKey: 'id',
// 체크박스 열을 둔 여러 행 선택. Shift+클릭은 범위, Ctrl+클릭은 하나씩 켜고 끄기, 포커스된 행에서 Space는 토글이에요.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
} as const;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log({
ko:
rows.length === 0
? '선택 없음'
: `${rows.length}행 선택 (${rows.map((r) => r.customer).join(', ')}) · 금액 합계 ${total.toLocaleString('ko-KR')}원`,
en:
rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount ${total.toLocaleString('en-US')} KRW`,
});
});
}
export const actions = {
// 방식을 바꾸면 이미 고른 행은 새 방식에 맞게 정리돼요(단일이면 하나만 남고, 끔이면 모두 풀려요).
mode: (api: GridApi<Row>, value?: string) => {
api.setOptions({
selection: MODES[(value as keyof typeof MODES) ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api: GridApi<Row>) => {
try {
api.setSelectedKeys([2, 4]);
} catch {
say({
ko: '이 방식에서는 두 행을 한꺼번에 고를 수 없어요',
en: 'This mode cannot select two rows at once',
});
}
},
clear: (api: GridApi<Row>) => api.clearSelection(),
};버튼을 누르면 이 예제의 코드가 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">
<select
aria-label="선택 방식"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="multipleCheck" selected>여러 행 + 체크박스 (기본)</option>
<option value="multiple">여러 행 (체크박스 없음)</option>
<option value="single">한 행만</option>
<option value="none">끔</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.pickTwo(api)"
>두 행 고르기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>선택 지우기</button>
</div>
<mx-grid style="height: 380px" [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;
customer: string;
status: string;
amount: number;
}
const customers = [
'한빛물류',
'푸른하늘식품',
'북극성무역',
'다온상사',
'새벽농원',
'모아패션',
'바다유통',
'해든전자',
];
const statuses = ['결제 완료', '대기', '연체'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: '고객사', width: 150 },
{ id: 'status', title: '상태', width: 110 },
{
id: 'amount',
title: '금액(원)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('ko-KR'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3] as string,
amount: 430000 + ((i * 613000) % 2900000),
})),
rowKey: 'id',
// 체크박스 열을 둔 여러 행 선택. Shift+클릭은 범위, Ctrl+클릭은 하나씩 켜고 끄기, 포커스된 행에서 Space는 토글이에요.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
} as const;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log({
ko:
rows.length === 0
? '선택 없음'
: `${rows.length}행 선택 (${rows.map((r) => r.customer).join(', ')}) · 금액 합계 ${total.toLocaleString('ko-KR')}원`,
en:
rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount ${total.toLocaleString('en-US')} KRW`,
});
});
}
export const actions = {
// 방식을 바꾸면 이미 고른 행은 새 방식에 맞게 정리돼요(단일이면 하나만 남고, 끔이면 모두 풀려요).
mode: (api: GridApi<Row>, value?: string) => {
api.setOptions({
selection: MODES[(value as keyof typeof MODES) ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api: GridApi<Row>) => {
try {
api.setSelectedKeys([2, 4]);
} catch {
say({
ko: '이 방식에서는 두 행을 한꺼번에 고를 수 없어요',
en: 'This mode cannot select two rows at once',
});
}
},
clear: (api: GridApi<Row>) => api.clearSelection(),
};When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<div id="app">
<div class="toolbar">
<select aria-label="Selection mode" id="mode">
<option value="multipleCheck" selected>Multiple + checkbox (default)</option>
<option value="multiple">Multiple (no checkbox)</option>
<option value="single">Single</option>
<option value="none">Off</option>
</select>
<button type="button" id="pickTwo">Pick two rows</button>
<button type="button" id="clear">Clear selection</button>
</div>
<div id="grid" style="height: 380px"></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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('pickTwo').addEventListener('click', () => actions.pickTwo(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const customers = [
'Bright Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Corp',
'Sunrise Farm',
'Moa Fashion',
'Ocean Retail',
'Haeden Electronics',
];
const statuses = ['Paid', 'Pending', 'Overdue'];
export const options = {
columns: [
{ id: 'customer', title: 'Customer', width: 170 },
{ id: 'status', title: 'Status', width: 110 },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3],
amount: 430 + ((i * 613) % 2900),
})),
rowKey: 'id',
// Multiple selection with a checkbox column. Shift+click selects a range, Ctrl+click toggles one row, Space on the focused row toggles it.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
};
let say = () => { };
export function setup(api, log) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log(rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount $${total.toLocaleString('en-US')}`);
});
}
export const actions = {
// Changing the mode adjusts rows already selected (single keeps one, none clears all).
mode: (api, value) => {
api.setOptions({
selection: MODES[value ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api) => {
try {
api.setSelectedKeys([2, 4]);
}
catch {
say('This mode cannot select two rows at once');
}
},
clear: (api) => api.clearSelection(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Row selection modes: single, multiple, checkbox</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Selection mode" id="mode">
<option value="multipleCheck" selected>Multiple + checkbox (default)</option>
<option value="multiple">Multiple (no checkbox)</option>
<option value="single">Single</option>
<option value="none">Off</option>
</select>
<button type="button" id="pickTwo">Pick two rows</button>
<button type="button" id="clear">Clear selection</button>
</div>
<div id="grid" style="height: 380px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const customers = [
'Bright Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Corp',
'Sunrise Farm',
'Moa Fashion',
'Ocean Retail',
'Haeden Electronics',
];
const statuses = ['Paid', 'Pending', 'Overdue'];
const options = {
columns: [
{ id: 'customer', title: 'Customer', width: 170 },
{ id: 'status', title: 'Status', width: 110 },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3],
amount: 430 + ((i * 613) % 2900),
})),
rowKey: 'id',
// Multiple selection with a checkbox column. Shift+click selects a range, Ctrl+click toggles one row, Space on the focused row toggles it.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
};
let say = () => { };
function setup(api, log) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log(rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount $${total.toLocaleString('en-US')}`);
});
}
const actions = {
// Changing the mode adjusts rows already selected (single keeps one, none clears all).
mode: (api, value) => {
api.setOptions({
selection: MODES[value ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api) => {
try {
api.setSelectedKeys([2, 4]);
}
catch {
say('This mode cannot select two rows at once');
}
},
clear: (api) => api.clearSelection(),
};
options.ariaLabel = "Row selection modes: single, multiple, checkbox";
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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
document.getElementById('pickTwo').addEventListener('click', () => actions.pickTwo(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(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">
<select
aria-label="Selection mode"
disabled={!api}
onChange={(event) => api && actions.mode(api, event.target.value)}
>
<option value="multipleCheck">Multiple + checkbox (default)</option>
<option value="multiple">Multiple (no checkbox)</option>
<option value="single">Single</option>
<option value="none">Off</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.pickTwo(api)}
>Pick two rows</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear selection</button>
</div>
<Grid style={{ height: 380 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
customer: string;
status: string;
amount: number;
}
const customers = [
'Bright Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Corp',
'Sunrise Farm',
'Moa Fashion',
'Ocean Retail',
'Haeden Electronics',
];
const statuses = ['Paid', 'Pending', 'Overdue'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: 'Customer', width: 170 },
{ id: 'status', title: 'Status', width: 110 },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3] as string,
amount: 430 + ((i * 613) % 2900),
})),
rowKey: 'id',
// Multiple selection with a checkbox column. Shift+click selects a range, Ctrl+click toggles one row, Space on the focused row toggles it.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
} as const;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log(
rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount $${total.toLocaleString('en-US')}`,
);
});
}
export const actions = {
// Changing the mode adjusts rows already selected (single keeps one, none clears all).
mode: (api: GridApi<Row>, value?: string) => {
api.setOptions({
selection: MODES[(value as keyof typeof MODES) ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api: GridApi<Row>) => {
try {
api.setSelectedKeys([2, 4]);
} catch {
say('This mode cannot select two rows at once');
}
},
clear: (api: GridApi<Row>) => api.clearSelection(),
};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">
<select
aria-label="Selection mode"
:disabled="!api"
@change="api && actions.mode(api, ($event.target as HTMLSelectElement).value)"
>
<option value="multipleCheck" selected>Multiple + checkbox (default)</option>
<option value="multiple">Multiple (no checkbox)</option>
<option value="single">Single</option>
<option value="none">Off</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.pickTwo(api)">Pick two rows</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear selection</button>
</div>
<Grid style="height: 380px" :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;
customer: string;
status: string;
amount: number;
}
const customers = [
'Bright Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Corp',
'Sunrise Farm',
'Moa Fashion',
'Ocean Retail',
'Haeden Electronics',
];
const statuses = ['Paid', 'Pending', 'Overdue'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: 'Customer', width: 170 },
{ id: 'status', title: 'Status', width: 110 },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3] as string,
amount: 430 + ((i * 613) % 2900),
})),
rowKey: 'id',
// Multiple selection with a checkbox column. Shift+click selects a range, Ctrl+click toggles one row, Space on the focused row toggles it.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
} as const;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log(
rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount $${total.toLocaleString('en-US')}`,
);
});
}
export const actions = {
// Changing the mode adjusts rows already selected (single keeps one, none clears all).
mode: (api: GridApi<Row>, value?: string) => {
api.setOptions({
selection: MODES[(value as keyof typeof MODES) ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api: GridApi<Row>) => {
try {
api.setSelectedKeys([2, 4]);
} catch {
say('This mode cannot select two rows at once');
}
},
clear: (api: GridApi<Row>) => api.clearSelection(),
};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">
<select
aria-label="Selection mode"
[disabled]="!api"
(change)="api && actions.mode(api, $any($event.target).value)"
>
<option value="multipleCheck" selected>Multiple + checkbox (default)</option>
<option value="multiple">Multiple (no checkbox)</option>
<option value="single">Single</option>
<option value="none">Off</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.pickTwo(api)"
>Pick two rows</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear selection</button>
</div>
<mx-grid style="height: 380px" [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;
customer: string;
status: string;
amount: number;
}
const customers = [
'Bright Logistics',
'Blue Sky Foods',
'Polaris Trading',
'Dawn Corp',
'Sunrise Farm',
'Moa Fashion',
'Ocean Retail',
'Haeden Electronics',
];
const statuses = ['Paid', 'Pending', 'Overdue'];
export const options: GridOptions<Row> = {
columns: [
{ id: 'customer', title: 'Customer', width: 170 },
{ id: 'status', title: 'Status', width: 110 },
{
id: 'amount',
title: 'Amount ($)',
kind: 'number',
width: 120,
align: 'end',
formatValue: (value) => Number(value).toLocaleString('en-US'),
},
],
rows: customers.map((customer, i) => ({
id: i + 1,
customer,
status: statuses[(i * 2) % 3] as string,
amount: 430 + ((i * 613) % 2900),
})),
rowKey: 'id',
// Multiple selection with a checkbox column. Shift+click selects a range, Ctrl+click toggles one row, Space on the focused row toggles it.
selection: { mode: 'multiple', checkbox: true },
};
const MODES = {
multipleCheck: { mode: 'multiple', checkbox: true },
multiple: 'multiple',
single: 'single',
none: 'none',
} as const;
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return api.on('selectionChanged', ({ selectedKeys }) => {
const rows = selectedKeys.map((key) => api.getRowByKey(key)).filter((row) => row !== undefined);
const total = rows.reduce((sum, row) => sum + row.amount, 0);
log(
rows.length === 0
? 'Nothing selected'
: `${rows.length} rows selected (${rows.map((r) => r.customer).join(', ')}) · total amount $${total.toLocaleString('en-US')}`,
);
});
}
export const actions = {
// Changing the mode adjusts rows already selected (single keeps one, none clears all).
mode: (api: GridApi<Row>, value?: string) => {
api.setOptions({
selection: MODES[(value as keyof typeof MODES) ?? 'multipleCheck'] ?? MODES.multipleCheck,
});
},
pickTwo: (api: GridApi<Row>) => {
try {
api.setSelectedKeys([2, 4]);
} catch {
say('This mode cannot select two rows at once');
}
},
clear: (api: GridApi<Row>) => api.clearSelection(),
};