전체 선택의 범위와 칸 선택Select all scopes and cell selection
selectAllRows의 범위(visible, page, filtered, all)에 따라 선택되는 행이 달라지고, selectAllCells와 selectColumnCells로 칸을 한꺼번에 골라요. 페이징과 필터가 있을 때 차이가 드러나요.selectAllRows selects different rows depending on the scope (visible, page, filtered, all), and selectAllCells and selectColumnCells pick cells in bulk. The difference shows with paging and a filter.
코드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="visible">visible</button>
<button type="button" id="page">page</button>
<button type="button" id="filtered">filtered</button>
<button type="button" id="all">all</button>
<button type="button" id="cells">칸 전체 선택</button>
<button type="button" id="column">이름 열 칸 선택</button>
<button type="button" id="clear">모두 풀기</button>
</div>
<div id="grid" style="height: 260px"></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('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('page').addEventListener('click', () => actions.page(api));
document.getElementById('filtered').addEventListener('click', () => actions.filtered(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('cells').addEventListener('click', () => actions.cells(api));
document.getElementById('column').addEventListener('click', () => actions.column(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
// 전체 선택에도 범위가 있어요: visible(헤더 체크박스와 같음), page(현재 페이지), filtered(필터를 통과한 모든 페이지), all(모든 행).
// 페이지당 5행이고, '개발'만 걸러 두면 네 가지 결과가 모두 달라요.
export const options = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['개발', '디자인', '영업'][i % 3],
name: names[i % 6],
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say = () => { };
export function setup(api, log) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) => log({ ko: `선택 ${selectedKeys.length}개`, en: `${selectedKeys.length} selected` }));
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: '개발' }]);
log({
ko: "'개발'만 걸러 두었어요(8행, 2페이지). 범위를 바꿔 전체 선택해 보세요.",
en: "Filtered to '개발' (8 rows, 2 pages). Try the select all scopes.",
});
return () => off();
}
const scope = (name, ko, en) => (api) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say({
ko: `${ko}: ${api.getSelectedKeys().length}행`,
en: `${en}: ${api.getSelectedKeys().length} rows`,
});
};
export const actions = {
visible: scope('visible', 'visible(헤더 체크박스와 같아요)', 'visible (same as the header checkbox)'),
page: scope('page', 'page(현재 페이지)', 'page (current page)'),
filtered: scope('filtered', 'filtered(필터를 통과한 모든 페이지)', 'filtered (all pages passing the filter)'),
all: scope('all', 'all(모든 행)', 'all (every row)'),
cells: (api) => {
api.selectAllCells();
say({
ko: `selectAllCells: 칸 ${api.getSelectedCells().length}개`,
en: `selectAllCells: ${api.getSelectedCells().length} cells`,
});
},
column: (api) => {
api.selectColumnCells('name');
say({
ko: `selectColumnCells('name'): 칸 ${api.getSelectedCells().length}개`,
en: `selectColumnCells('name'): ${api.getSelectedCells().length} cells`,
});
},
clear: (api) => {
api.deselectAllRows();
api.clearCellSelection();
},
};<!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="visible">visible</button>
<button type="button" id="page">page</button>
<button type="button" id="filtered">filtered</button>
<button type="button" id="all">all</button>
<button type="button" id="cells">칸 전체 선택</button>
<button type="button" id="column">이름 열 칸 선택</button>
<button type="button" id="clear">모두 풀기</button>
</div>
<div id="grid" style="height: 260px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
// 전체 선택에도 범위가 있어요: visible(헤더 체크박스와 같음), page(현재 페이지), filtered(필터를 통과한 모든 페이지), all(모든 행).
// 페이지당 5행이고, '개발'만 걸러 두면 네 가지 결과가 모두 달라요.
const options = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['개발', '디자인', '영업'][i % 3],
name: names[i % 6],
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say = () => { };
function setup(api, log) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) => log({ ko: `선택 ${selectedKeys.length}개`, en: `${selectedKeys.length} selected` }));
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: '개발' }]);
log({
ko: "'개발'만 걸러 두었어요(8행, 2페이지). 범위를 바꿔 전체 선택해 보세요.",
en: "Filtered to '개발' (8 rows, 2 pages). Try the select all scopes.",
});
return () => off();
}
const scope = (name, ko, en) => (api) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say({
ko: `${ko}: ${api.getSelectedKeys().length}행`,
en: `${en}: ${api.getSelectedKeys().length} rows`,
});
};
const actions = {
visible: scope('visible', 'visible(헤더 체크박스와 같아요)', 'visible (same as the header checkbox)'),
page: scope('page', 'page(현재 페이지)', 'page (current page)'),
filtered: scope('filtered', 'filtered(필터를 통과한 모든 페이지)', 'filtered (all pages passing the filter)'),
all: scope('all', 'all(모든 행)', 'all (every row)'),
cells: (api) => {
api.selectAllCells();
say({
ko: `selectAllCells: 칸 ${api.getSelectedCells().length}개`,
en: `selectAllCells: ${api.getSelectedCells().length} cells`,
});
},
column: (api) => {
api.selectColumnCells('name');
say({
ko: `selectColumnCells('name'): 칸 ${api.getSelectedCells().length}개`,
en: `selectColumnCells('name'): ${api.getSelectedCells().length} cells`,
});
},
clear: (api) => {
api.deselectAllRows();
api.clearCellSelection();
},
};
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('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('page').addEventListener('click', () => actions.page(api));
document.getElementById('filtered').addEventListener('click', () => actions.filtered(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('cells').addEventListener('click', () => actions.cells(api));
document.getElementById('column').addEventListener('click', () => actions.column(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.visible(api)}
>visible</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.page(api)}
>page</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.filtered(api)}
>filtered</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.cells(api)}
>칸 전체 선택</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.column(api)}
>이름 열 칸 선택</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>모두 풀기</button>
</div>
<Grid style={{ height: 260 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
name: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
// 전체 선택에도 범위가 있어요: visible(헤더 체크박스와 같음), page(현재 페이지), filtered(필터를 통과한 모든 페이지), all(모든 행).
// 페이지당 5행이고, '개발'만 걸러 두면 네 가지 결과가 모두 달라요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['개발', '디자인', '영업'][i % 3] as string,
name: names[i % 6] as string,
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) =>
log({ ko: `선택 ${selectedKeys.length}개`, en: `${selectedKeys.length} selected` }),
);
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: '개발' }]);
log({
ko: "'개발'만 걸러 두었어요(8행, 2페이지). 범위를 바꿔 전체 선택해 보세요.",
en: "Filtered to '개발' (8 rows, 2 pages). Try the select all scopes.",
});
return () => off();
}
const scope =
(name: 'visible' | 'page' | 'filtered' | 'all', ko: string, en: string) =>
(api: GridApi<Row>) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say({
ko: `${ko}: ${api.getSelectedKeys().length}행`,
en: `${en}: ${api.getSelectedKeys().length} rows`,
});
};
export const actions = {
visible: scope(
'visible',
'visible(헤더 체크박스와 같아요)',
'visible (same as the header checkbox)',
),
page: scope('page', 'page(현재 페이지)', 'page (current page)'),
filtered: scope(
'filtered',
'filtered(필터를 통과한 모든 페이지)',
'filtered (all pages passing the filter)',
),
all: scope('all', 'all(모든 행)', 'all (every row)'),
cells: (api: GridApi<Row>) => {
api.selectAllCells();
say({
ko: `selectAllCells: 칸 ${api.getSelectedCells().length}개`,
en: `selectAllCells: ${api.getSelectedCells().length} cells`,
});
},
column: (api: GridApi<Row>) => {
api.selectColumnCells('name');
say({
ko: `selectColumnCells('name'): 칸 ${api.getSelectedCells().length}개`,
en: `selectColumnCells('name'): ${api.getSelectedCells().length} cells`,
});
},
clear: (api: GridApi<Row>) => {
api.deselectAllRows();
api.clearCellSelection();
},
};버튼을 누르면 이 예제의 코드가 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.visible(api)">visible</button>
<button type="button" :disabled="!api" @click="api && actions.page(api)">page</button>
<button
type="button"
:disabled="!api"
@click="api && actions.filtered(api)"
>filtered</button>
<button type="button" :disabled="!api" @click="api && actions.all(api)">all</button>
<button type="button" :disabled="!api" @click="api && actions.cells(api)">칸 전체 선택</button>
<button type="button" :disabled="!api" @click="api && actions.column(api)">이름 열 칸 선택</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">모두 풀기</button>
</div>
<Grid style="height: 260px" :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;
team: string;
name: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
// 전체 선택에도 범위가 있어요: visible(헤더 체크박스와 같음), page(현재 페이지), filtered(필터를 통과한 모든 페이지), all(모든 행).
// 페이지당 5행이고, '개발'만 걸러 두면 네 가지 결과가 모두 달라요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['개발', '디자인', '영업'][i % 3] as string,
name: names[i % 6] as string,
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) =>
log({ ko: `선택 ${selectedKeys.length}개`, en: `${selectedKeys.length} selected` }),
);
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: '개발' }]);
log({
ko: "'개발'만 걸러 두었어요(8행, 2페이지). 범위를 바꿔 전체 선택해 보세요.",
en: "Filtered to '개발' (8 rows, 2 pages). Try the select all scopes.",
});
return () => off();
}
const scope =
(name: 'visible' | 'page' | 'filtered' | 'all', ko: string, en: string) =>
(api: GridApi<Row>) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say({
ko: `${ko}: ${api.getSelectedKeys().length}행`,
en: `${en}: ${api.getSelectedKeys().length} rows`,
});
};
export const actions = {
visible: scope(
'visible',
'visible(헤더 체크박스와 같아요)',
'visible (same as the header checkbox)',
),
page: scope('page', 'page(현재 페이지)', 'page (current page)'),
filtered: scope(
'filtered',
'filtered(필터를 통과한 모든 페이지)',
'filtered (all pages passing the filter)',
),
all: scope('all', 'all(모든 행)', 'all (every row)'),
cells: (api: GridApi<Row>) => {
api.selectAllCells();
say({
ko: `selectAllCells: 칸 ${api.getSelectedCells().length}개`,
en: `selectAllCells: ${api.getSelectedCells().length} cells`,
});
},
column: (api: GridApi<Row>) => {
api.selectColumnCells('name');
say({
ko: `selectColumnCells('name'): 칸 ${api.getSelectedCells().length}개`,
en: `selectColumnCells('name'): ${api.getSelectedCells().length} cells`,
});
},
clear: (api: GridApi<Row>) => {
api.deselectAllRows();
api.clearCellSelection();
},
};버튼을 누르면 이 예제의 코드가 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.visible(api)"
>visible</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.page(api)"
>page</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.filtered(api)"
>filtered</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.cells(api)"
>칸 전체 선택</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.column(api)"
>이름 열 칸 선택</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>모두 풀기</button>
</div>
<mx-grid style="height: 260px" [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;
team: string;
name: string;
}
const names = ['김민준', '이서연', '박지호', '최유나', '정도윤', '한소희'];
// 전체 선택에도 범위가 있어요: visible(헤더 체크박스와 같음), page(현재 페이지), filtered(필터를 통과한 모든 페이지), all(모든 행).
// 페이지당 5행이고, '개발'만 걸러 두면 네 가지 결과가 모두 달라요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: '팀', width: 90 },
{ id: 'name', title: '이름', width: 110 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['개발', '디자인', '영업'][i % 3] as string,
name: names[i % 6] as string,
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) =>
log({ ko: `선택 ${selectedKeys.length}개`, en: `${selectedKeys.length} selected` }),
);
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: '개발' }]);
log({
ko: "'개발'만 걸러 두었어요(8행, 2페이지). 범위를 바꿔 전체 선택해 보세요.",
en: "Filtered to '개발' (8 rows, 2 pages). Try the select all scopes.",
});
return () => off();
}
const scope =
(name: 'visible' | 'page' | 'filtered' | 'all', ko: string, en: string) =>
(api: GridApi<Row>) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say({
ko: `${ko}: ${api.getSelectedKeys().length}행`,
en: `${en}: ${api.getSelectedKeys().length} rows`,
});
};
export const actions = {
visible: scope(
'visible',
'visible(헤더 체크박스와 같아요)',
'visible (same as the header checkbox)',
),
page: scope('page', 'page(현재 페이지)', 'page (current page)'),
filtered: scope(
'filtered',
'filtered(필터를 통과한 모든 페이지)',
'filtered (all pages passing the filter)',
),
all: scope('all', 'all(모든 행)', 'all (every row)'),
cells: (api: GridApi<Row>) => {
api.selectAllCells();
say({
ko: `selectAllCells: 칸 ${api.getSelectedCells().length}개`,
en: `selectAllCells: ${api.getSelectedCells().length} cells`,
});
},
column: (api: GridApi<Row>) => {
api.selectColumnCells('name');
say({
ko: `selectColumnCells('name'): 칸 ${api.getSelectedCells().length}개`,
en: `selectColumnCells('name'): ${api.getSelectedCells().length} cells`,
});
},
clear: (api: GridApi<Row>) => {
api.deselectAllRows();
api.clearCellSelection();
},
};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="visible">visible</button>
<button type="button" id="page">page</button>
<button type="button" id="filtered">filtered</button>
<button type="button" id="all">all</button>
<button type="button" id="cells">Select all cells</button>
<button type="button" id="column">Select Name column cells</button>
<button type="button" id="clear">Clear all</button>
</div>
<div id="grid" style="height: 260px"></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('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('page').addEventListener('click', () => actions.page(api));
document.getElementById('filtered').addEventListener('click', () => actions.filtered(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('cells').addEventListener('click', () => actions.cells(api));
document.getElementById('column').addEventListener('click', () => actions.column(api));
document.getElementById('clear').addEventListener('click', () => actions.clear(api));const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
// Select all has scopes too: visible (same as the header checkbox), page (current page), filtered (every page passing the filter), all (every row).
// With 5 rows per page and only 'Dev' filtered, all four give different results.
export const options = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 130 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['Dev', 'Design', 'Sales'][i % 3],
name: names[i % 6],
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say = () => { };
export function setup(api, log) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) => log(`${selectedKeys.length} selected`));
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: 'Dev' }]);
log("Filtered to 'Dev' (8 rows, 2 pages). Try the select all scopes.");
return () => off();
}
const scope = (name, label) => (api) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say(`${label}: ${api.getSelectedKeys().length} rows`);
};
export const actions = {
visible: scope('visible', 'visible (same as the header checkbox)'),
page: scope('page', 'page (current page)'),
filtered: scope('filtered', 'filtered (all pages passing the filter)'),
all: scope('all', 'all (every row)'),
cells: (api) => {
api.selectAllCells();
say(`selectAllCells: ${api.getSelectedCells().length} cells`);
},
column: (api) => {
api.selectColumnCells('name');
say(`selectColumnCells('name'): ${api.getSelectedCells().length} cells`);
},
clear: (api) => {
api.deselectAllRows();
api.clearCellSelection();
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Select all scopes and cell selection</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="visible">visible</button>
<button type="button" id="page">page</button>
<button type="button" id="filtered">filtered</button>
<button type="button" id="all">all</button>
<button type="button" id="cells">Select all cells</button>
<button type="button" id="column">Select Name column cells</button>
<button type="button" id="clear">Clear all</button>
</div>
<div id="grid" style="height: 260px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
// Select all has scopes too: visible (same as the header checkbox), page (current page), filtered (every page passing the filter), all (every row).
// With 5 rows per page and only 'Dev' filtered, all four give different results.
const options = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 130 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['Dev', 'Design', 'Sales'][i % 3],
name: names[i % 6],
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say = () => { };
function setup(api, log) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) => log(`${selectedKeys.length} selected`));
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: 'Dev' }]);
log("Filtered to 'Dev' (8 rows, 2 pages). Try the select all scopes.");
return () => off();
}
const scope = (name, label) => (api) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say(`${label}: ${api.getSelectedKeys().length} rows`);
};
const actions = {
visible: scope('visible', 'visible (same as the header checkbox)'),
page: scope('page', 'page (current page)'),
filtered: scope('filtered', 'filtered (all pages passing the filter)'),
all: scope('all', 'all (every row)'),
cells: (api) => {
api.selectAllCells();
say(`selectAllCells: ${api.getSelectedCells().length} cells`);
},
column: (api) => {
api.selectColumnCells('name');
say(`selectColumnCells('name'): ${api.getSelectedCells().length} cells`);
},
clear: (api) => {
api.deselectAllRows();
api.clearCellSelection();
},
};
options.ariaLabel = "Select all scopes and cell selection";
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('visible').addEventListener('click', () => actions.visible(api));
document.getElementById('page').addEventListener('click', () => actions.page(api));
document.getElementById('filtered').addEventListener('click', () => actions.filtered(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('cells').addEventListener('click', () => actions.cells(api));
document.getElementById('column').addEventListener('click', () => actions.column(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">
<button
type="button"
disabled={!api}
onClick={() => api && actions.visible(api)}
>visible</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.page(api)}
>page</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.filtered(api)}
>filtered</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.cells(api)}
>Select all cells</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.column(api)}
>Select Name column cells</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.clear(api)}
>Clear all</button>
</div>
<Grid style={{ height: 260 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
name: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
// Select all has scopes too: visible (same as the header checkbox), page (current page), filtered (every page passing the filter), all (every row).
// With 5 rows per page and only 'Dev' filtered, all four give different results.
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 130 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['Dev', 'Design', 'Sales'][i % 3] as string,
name: names[i % 6] as string,
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) =>
log(`${selectedKeys.length} selected`),
);
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: 'Dev' }]);
log("Filtered to 'Dev' (8 rows, 2 pages). Try the select all scopes.");
return () => off();
}
const scope =
(name: 'visible' | 'page' | 'filtered' | 'all', label: string) => (api: GridApi<Row>) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say(`${label}: ${api.getSelectedKeys().length} rows`);
};
export const actions = {
visible: scope('visible', 'visible (same as the header checkbox)'),
page: scope('page', 'page (current page)'),
filtered: scope('filtered', 'filtered (all pages passing the filter)'),
all: scope('all', 'all (every row)'),
cells: (api: GridApi<Row>) => {
api.selectAllCells();
say(`selectAllCells: ${api.getSelectedCells().length} cells`);
},
column: (api: GridApi<Row>) => {
api.selectColumnCells('name');
say(`selectColumnCells('name'): ${api.getSelectedCells().length} cells`);
},
clear: (api: GridApi<Row>) => {
api.deselectAllRows();
api.clearCellSelection();
},
};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.visible(api)">visible</button>
<button type="button" :disabled="!api" @click="api && actions.page(api)">page</button>
<button
type="button"
:disabled="!api"
@click="api && actions.filtered(api)"
>filtered</button>
<button type="button" :disabled="!api" @click="api && actions.all(api)">all</button>
<button type="button" :disabled="!api" @click="api && actions.cells(api)">Select all cells</button>
<button type="button" :disabled="!api" @click="api && actions.column(api)">Select Name column cells</button>
<button type="button" :disabled="!api" @click="api && actions.clear(api)">Clear all</button>
</div>
<Grid style="height: 260px" :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;
team: string;
name: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
// Select all has scopes too: visible (same as the header checkbox), page (current page), filtered (every page passing the filter), all (every row).
// With 5 rows per page and only 'Dev' filtered, all four give different results.
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 130 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['Dev', 'Design', 'Sales'][i % 3] as string,
name: names[i % 6] as string,
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) =>
log(`${selectedKeys.length} selected`),
);
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: 'Dev' }]);
log("Filtered to 'Dev' (8 rows, 2 pages). Try the select all scopes.");
return () => off();
}
const scope =
(name: 'visible' | 'page' | 'filtered' | 'all', label: string) => (api: GridApi<Row>) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say(`${label}: ${api.getSelectedKeys().length} rows`);
};
export const actions = {
visible: scope('visible', 'visible (same as the header checkbox)'),
page: scope('page', 'page (current page)'),
filtered: scope('filtered', 'filtered (all pages passing the filter)'),
all: scope('all', 'all (every row)'),
cells: (api: GridApi<Row>) => {
api.selectAllCells();
say(`selectAllCells: ${api.getSelectedCells().length} cells`);
},
column: (api: GridApi<Row>) => {
api.selectColumnCells('name');
say(`selectColumnCells('name'): ${api.getSelectedCells().length} cells`);
},
clear: (api: GridApi<Row>) => {
api.deselectAllRows();
api.clearCellSelection();
},
};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.visible(api)"
>visible</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.page(api)"
>page</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.filtered(api)"
>filtered</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.cells(api)"
>Select all cells</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.column(api)"
>Select Name column cells</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.clear(api)"
>Clear all</button>
</div>
<mx-grid style="height: 260px" [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;
team: string;
name: string;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Reed',
'Olivia Hayes',
'Ethan Brooks',
'Ava Morgan',
];
// Select all has scopes too: visible (same as the header checkbox), page (current page), filtered (every page passing the filter), all (every row).
// With 5 rows per page and only 'Dev' filtered, all four give different results.
export const options: GridOptions<Row> = {
columns: [
{ id: 'team', title: 'Team', width: 90 },
{ id: 'name', title: 'Name', width: 130 },
],
rows: Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
team: ['Dev', 'Design', 'Sales'][i % 3] as string,
name: names[i % 6] as string,
})),
rowKey: 'id',
selection: { mode: 'multiple', checkbox: true },
cellSelection: 'multiple',
pagination: { mode: 'client', pageSize: 5 },
filterRow: true,
};
let say: (message: LogText) => void = () => {};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
const off = api.on('selectionChanged', ({ selectedKeys }) =>
log(`${selectedKeys.length} selected`),
);
api.setColumnFilter('team', [{ columnId: 'team', operator: 'equals', value: 'Dev' }]);
log("Filtered to 'Dev' (8 rows, 2 pages). Try the select all scopes.");
return () => off();
}
const scope =
(name: 'visible' | 'page' | 'filtered' | 'all', label: string) => (api: GridApi<Row>) => {
api.deselectAllRows();
api.selectAllRows({ scope: name });
say(`${label}: ${api.getSelectedKeys().length} rows`);
};
export const actions = {
visible: scope('visible', 'visible (same as the header checkbox)'),
page: scope('page', 'page (current page)'),
filtered: scope('filtered', 'filtered (all pages passing the filter)'),
all: scope('all', 'all (every row)'),
cells: (api: GridApi<Row>) => {
api.selectAllCells();
say(`selectAllCells: ${api.getSelectedCells().length} cells`);
},
column: (api: GridApi<Row>) => {
api.selectColumnCells('name');
say(`selectColumnCells('name'): ${api.getSelectedCells().length} cells`);
},
clear: (api: GridApi<Row>) => {
api.deselectAllRows();
api.clearCellSelection();
},
};