부모를 고르면 자식도 함께 고르기Select a parent and its children together
tree.checkCascade를 켜면 행을 선택할 때 후손도, 풀 때도 후손이 함께 움직여요. 체크박스에서 후손이 일부만 선택되면 상위 행이 어중간한 표시로 바뀌어요. tree.expandRecursive는 펼칠 때 후손도 펼쳐요.With tree.checkCascade, selecting a row selects its descendants and deselecting does the same. With checkboxes a parent shows a mixed state when only some descendants are selected. tree.expandRecursive expands all descendants at once.
코드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="all">모두 접기</button>
<button type="button" id="log">선택 키 보기</button>
</div>
<div id="grid" style="height: 320px"></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('all').addEventListener('click', () => actions.all(api));
document.getElementById('log').addEventListener('click', () => actions.log(api));const ROWS = [
{ id: 1, parent: null, name: '대표', title: '대표이사' },
{ id: 2, parent: 1, name: '개발본부', title: '본부장' },
{ id: 3, parent: 2, name: '플랫폼팀', title: '팀장' },
{ id: 4, parent: 3, name: '김민준', title: '선임' },
{ id: 5, parent: 3, name: '이서연', title: '사원' },
{ id: 6, parent: 2, name: '앱팀', title: '팀장' },
{ id: 7, parent: 6, name: '박지호', title: '선임' },
{ id: 8, parent: 1, name: '경영지원', title: '본부장' },
{ id: 9, parent: 8, name: '인사팀', title: '팀장' },
{ id: 10, parent: 9, name: '최유나', title: '사원' },
];
const base = {
columns: [
{ id: 'name', title: '조직·이름', width: 180 },
{ id: 'title', title: '직함', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
let say = () => { };
export function setup(_api, log) {
say = log;
return () => { };
}
export const options = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// 본부장급 아래만 처음부터 펼쳐 둬요(그 밖의 행은 expandDepth를 따라요).
expandWhen: (row) => (row.title === '대표이사' ? true : undefined),
},
};
export const actions = {
all: (api) => api.collapseAll(),
log: (api) => say({
ko: `선택된 키: ${api.getSelectedKeys().join(', ') || '없음'}`,
en: `Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`,
}),
};<!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="all">모두 접기</button>
<button type="button" id="log">선택 키 보기</button>
</div>
<div id="grid" style="height: 320px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const ROWS = [
{ id: 1, parent: null, name: '대표', title: '대표이사' },
{ id: 2, parent: 1, name: '개발본부', title: '본부장' },
{ id: 3, parent: 2, name: '플랫폼팀', title: '팀장' },
{ id: 4, parent: 3, name: '김민준', title: '선임' },
{ id: 5, parent: 3, name: '이서연', title: '사원' },
{ id: 6, parent: 2, name: '앱팀', title: '팀장' },
{ id: 7, parent: 6, name: '박지호', title: '선임' },
{ id: 8, parent: 1, name: '경영지원', title: '본부장' },
{ id: 9, parent: 8, name: '인사팀', title: '팀장' },
{ id: 10, parent: 9, name: '최유나', title: '사원' },
];
const base = {
columns: [
{ id: 'name', title: '조직·이름', width: 180 },
{ id: 'title', title: '직함', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
let say = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
const options = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// 본부장급 아래만 처음부터 펼쳐 둬요(그 밖의 행은 expandDepth를 따라요).
expandWhen: (row) => (row.title === '대표이사' ? true : undefined),
},
};
const actions = {
all: (api) => api.collapseAll(),
log: (api) => say({
ko: `선택된 키: ${api.getSelectedKeys().join(', ') || '없음'}`,
en: `Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`,
}),
};
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('all').addEventListener('click', () => actions.all(api));
document.getElementById('log').addEventListener('click', () => actions.log(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.all(api)}
>모두 접기</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.log(api)}
>선택 키 보기</button>
</div>
<Grid style={{ height: 320 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
parent: number | null;
name: string;
title: string;
}
const ROWS: Row[] = [
{ id: 1, parent: null, name: '대표', title: '대표이사' },
{ id: 2, parent: 1, name: '개발본부', title: '본부장' },
{ id: 3, parent: 2, name: '플랫폼팀', title: '팀장' },
{ id: 4, parent: 3, name: '김민준', title: '선임' },
{ id: 5, parent: 3, name: '이서연', title: '사원' },
{ id: 6, parent: 2, name: '앱팀', title: '팀장' },
{ id: 7, parent: 6, name: '박지호', title: '선임' },
{ id: 8, parent: 1, name: '경영지원', title: '본부장' },
{ id: 9, parent: 8, name: '인사팀', title: '팀장' },
{ id: 10, parent: 9, name: '최유나', title: '사원' },
];
const base = {
columns: [
{ id: 'name', title: '조직·이름', width: 180 },
{ id: 'title', title: '직함', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const options: GridOptions<Row> = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// 본부장급 아래만 처음부터 펼쳐 둬요(그 밖의 행은 expandDepth를 따라요).
expandWhen: (row) => (row.title === '대표이사' ? true : undefined),
},
};
export const actions = {
all: (api: GridApi<Row>) => api.collapseAll(),
log: (api: GridApi<Row>) =>
say({
ko: `선택된 키: ${api.getSelectedKeys().join(', ') || '없음'}`,
en: `Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`,
}),
};버튼을 누르면 이 예제의 코드가 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.all(api)">모두 접기</button>
<button type="button" :disabled="!api" @click="api && actions.log(api)">선택 키 보기</button>
</div>
<Grid style="height: 320px" :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;
parent: number | null;
name: string;
title: string;
}
const ROWS: Row[] = [
{ id: 1, parent: null, name: '대표', title: '대표이사' },
{ id: 2, parent: 1, name: '개발본부', title: '본부장' },
{ id: 3, parent: 2, name: '플랫폼팀', title: '팀장' },
{ id: 4, parent: 3, name: '김민준', title: '선임' },
{ id: 5, parent: 3, name: '이서연', title: '사원' },
{ id: 6, parent: 2, name: '앱팀', title: '팀장' },
{ id: 7, parent: 6, name: '박지호', title: '선임' },
{ id: 8, parent: 1, name: '경영지원', title: '본부장' },
{ id: 9, parent: 8, name: '인사팀', title: '팀장' },
{ id: 10, parent: 9, name: '최유나', title: '사원' },
];
const base = {
columns: [
{ id: 'name', title: '조직·이름', width: 180 },
{ id: 'title', title: '직함', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const options: GridOptions<Row> = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// 본부장급 아래만 처음부터 펼쳐 둬요(그 밖의 행은 expandDepth를 따라요).
expandWhen: (row) => (row.title === '대표이사' ? true : undefined),
},
};
export const actions = {
all: (api: GridApi<Row>) => api.collapseAll(),
log: (api: GridApi<Row>) =>
say({
ko: `선택된 키: ${api.getSelectedKeys().join(', ') || '없음'}`,
en: `Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`,
}),
};버튼을 누르면 이 예제의 코드가 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.all(api)"
>모두 접기</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.log(api)"
>선택 키 보기</button>
</div>
<mx-grid style="height: 320px" [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;
parent: number | null;
name: string;
title: string;
}
const ROWS: Row[] = [
{ id: 1, parent: null, name: '대표', title: '대표이사' },
{ id: 2, parent: 1, name: '개발본부', title: '본부장' },
{ id: 3, parent: 2, name: '플랫폼팀', title: '팀장' },
{ id: 4, parent: 3, name: '김민준', title: '선임' },
{ id: 5, parent: 3, name: '이서연', title: '사원' },
{ id: 6, parent: 2, name: '앱팀', title: '팀장' },
{ id: 7, parent: 6, name: '박지호', title: '선임' },
{ id: 8, parent: 1, name: '경영지원', title: '본부장' },
{ id: 9, parent: 8, name: '인사팀', title: '팀장' },
{ id: 10, parent: 9, name: '최유나', title: '사원' },
];
const base = {
columns: [
{ id: 'name', title: '조직·이름', width: 180 },
{ id: 'title', title: '직함', width: 120 },
],
rows: ROWS,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const options: GridOptions<Row> = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// 본부장급 아래만 처음부터 펼쳐 둬요(그 밖의 행은 expandDepth를 따라요).
expandWhen: (row) => (row.title === '대표이사' ? true : undefined),
},
};
export const actions = {
all: (api: GridApi<Row>) => api.collapseAll(),
log: (api: GridApi<Row>) =>
say({
ko: `선택된 키: ${api.getSelectedKeys().join(', ') || '없음'}`,
en: `Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`,
}),
};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="all">Collapse all</button>
<button type="button" id="log">Show selected keys</button>
</div>
<div id="grid" style="height: 320px"></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('all').addEventListener('click', () => actions.all(api));
document.getElementById('log').addEventListener('click', () => actions.log(api));const ROWS = [
{ id: 1, parent: null, name: 'CEO', title: 'Chief Executive' },
{ id: 2, parent: 1, name: 'Dev', title: 'Director' },
{ id: 3, parent: 2, name: 'Platform Team', title: 'Team Lead' },
{ id: 4, parent: 3, name: 'Liam Carter', title: 'Senior' },
{ id: 5, parent: 3, name: 'Emma Stone', title: 'Staff' },
{ id: 6, parent: 2, name: 'App Team', title: 'Team Lead' },
{ id: 7, parent: 6, name: 'Noah Davis', title: 'Senior' },
{ id: 8, parent: 1, name: 'Management Support', title: 'Director' },
{ id: 9, parent: 8, name: 'HR Team', title: 'Team Lead' },
{ id: 10, parent: 9, name: 'Mia Parker', title: 'Staff' },
];
const base = {
columns: [
{ id: 'name', title: 'Unit / Name', width: 180 },
{ id: 'title', title: 'Title', width: 140 },
],
rows: ROWS,
rowKey: 'id',
};
let say = () => { };
export function setup(_api, log) {
say = log;
return () => { };
}
export const options = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// Only the top row starts open (other rows follow expandDepth).
expandWhen: (row) => (row.title === 'Chief Executive' ? true : undefined),
},
};
export const actions = {
all: (api) => api.collapseAll(),
log: (api) => say(`Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Select a parent and its children together</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="all">Collapse all</button>
<button type="button" id="log">Show selected keys</button>
</div>
<div id="grid" style="height: 320px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const ROWS = [
{ id: 1, parent: null, name: 'CEO', title: 'Chief Executive' },
{ id: 2, parent: 1, name: 'Dev', title: 'Director' },
{ id: 3, parent: 2, name: 'Platform Team', title: 'Team Lead' },
{ id: 4, parent: 3, name: 'Liam Carter', title: 'Senior' },
{ id: 5, parent: 3, name: 'Emma Stone', title: 'Staff' },
{ id: 6, parent: 2, name: 'App Team', title: 'Team Lead' },
{ id: 7, parent: 6, name: 'Noah Davis', title: 'Senior' },
{ id: 8, parent: 1, name: 'Management Support', title: 'Director' },
{ id: 9, parent: 8, name: 'HR Team', title: 'Team Lead' },
{ id: 10, parent: 9, name: 'Mia Parker', title: 'Staff' },
];
const base = {
columns: [
{ id: 'name', title: 'Unit / Name', width: 180 },
{ id: 'title', title: 'Title', width: 140 },
],
rows: ROWS,
rowKey: 'id',
};
let say = () => { };
function setup(_api, log) {
say = log;
return () => { };
}
const options = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// Only the top row starts open (other rows follow expandDepth).
expandWhen: (row) => (row.title === 'Chief Executive' ? true : undefined),
},
};
const actions = {
all: (api) => api.collapseAll(),
log: (api) => say(`Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`),
};
options.ariaLabel = "Select a parent and its children together";
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('all').addEventListener('click', () => actions.all(api));
document.getElementById('log').addEventListener('click', () => actions.log(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.all(api)}
>Collapse all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.log(api)}
>Show selected keys</button>
</div>
<Grid style={{ height: 320 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
parent: number | null;
name: string;
title: string;
}
const ROWS: Row[] = [
{ id: 1, parent: null, name: 'CEO', title: 'Chief Executive' },
{ id: 2, parent: 1, name: 'Dev', title: 'Director' },
{ id: 3, parent: 2, name: 'Platform Team', title: 'Team Lead' },
{ id: 4, parent: 3, name: 'Liam Carter', title: 'Senior' },
{ id: 5, parent: 3, name: 'Emma Stone', title: 'Staff' },
{ id: 6, parent: 2, name: 'App Team', title: 'Team Lead' },
{ id: 7, parent: 6, name: 'Noah Davis', title: 'Senior' },
{ id: 8, parent: 1, name: 'Management Support', title: 'Director' },
{ id: 9, parent: 8, name: 'HR Team', title: 'Team Lead' },
{ id: 10, parent: 9, name: 'Mia Parker', title: 'Staff' },
];
const base = {
columns: [
{ id: 'name', title: 'Unit / Name', width: 180 },
{ id: 'title', title: 'Title', width: 140 },
],
rows: ROWS,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const options: GridOptions<Row> = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// Only the top row starts open (other rows follow expandDepth).
expandWhen: (row) => (row.title === 'Chief Executive' ? true : undefined),
},
};
export const actions = {
all: (api: GridApi<Row>) => api.collapseAll(),
log: (api: GridApi<Row>) => say(`Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`),
};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.all(api)">Collapse all</button>
<button type="button" :disabled="!api" @click="api && actions.log(api)">Show selected keys</button>
</div>
<Grid style="height: 320px" :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;
parent: number | null;
name: string;
title: string;
}
const ROWS: Row[] = [
{ id: 1, parent: null, name: 'CEO', title: 'Chief Executive' },
{ id: 2, parent: 1, name: 'Dev', title: 'Director' },
{ id: 3, parent: 2, name: 'Platform Team', title: 'Team Lead' },
{ id: 4, parent: 3, name: 'Liam Carter', title: 'Senior' },
{ id: 5, parent: 3, name: 'Emma Stone', title: 'Staff' },
{ id: 6, parent: 2, name: 'App Team', title: 'Team Lead' },
{ id: 7, parent: 6, name: 'Noah Davis', title: 'Senior' },
{ id: 8, parent: 1, name: 'Management Support', title: 'Director' },
{ id: 9, parent: 8, name: 'HR Team', title: 'Team Lead' },
{ id: 10, parent: 9, name: 'Mia Parker', title: 'Staff' },
];
const base = {
columns: [
{ id: 'name', title: 'Unit / Name', width: 180 },
{ id: 'title', title: 'Title', width: 140 },
],
rows: ROWS,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const options: GridOptions<Row> = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// Only the top row starts open (other rows follow expandDepth).
expandWhen: (row) => (row.title === 'Chief Executive' ? true : undefined),
},
};
export const actions = {
all: (api: GridApi<Row>) => api.collapseAll(),
log: (api: GridApi<Row>) => say(`Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`),
};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.all(api)"
>Collapse all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.log(api)"
>Show selected keys</button>
</div>
<mx-grid style="height: 320px" [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;
parent: number | null;
name: string;
title: string;
}
const ROWS: Row[] = [
{ id: 1, parent: null, name: 'CEO', title: 'Chief Executive' },
{ id: 2, parent: 1, name: 'Dev', title: 'Director' },
{ id: 3, parent: 2, name: 'Platform Team', title: 'Team Lead' },
{ id: 4, parent: 3, name: 'Liam Carter', title: 'Senior' },
{ id: 5, parent: 3, name: 'Emma Stone', title: 'Staff' },
{ id: 6, parent: 2, name: 'App Team', title: 'Team Lead' },
{ id: 7, parent: 6, name: 'Noah Davis', title: 'Senior' },
{ id: 8, parent: 1, name: 'Management Support', title: 'Director' },
{ id: 9, parent: 8, name: 'HR Team', title: 'Team Lead' },
{ id: 10, parent: 9, name: 'Mia Parker', title: 'Staff' },
];
const base = {
columns: [
{ id: 'name', title: 'Unit / Name', width: 180 },
{ id: 'title', title: 'Title', width: 140 },
],
rows: ROWS,
rowKey: 'id',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
return () => {};
}
export const options: GridOptions<Row> = {
...base,
selection: { mode: 'multiple', checkbox: true },
tree: {
parentKey: 'parent',
column: 'name',
expandDepth: 0,
checkCascade: true,
expandRecursive: true,
// Only the top row starts open (other rows follow expandDepth).
expandWhen: (row) => (row.title === 'Chief Executive' ? true : undefined),
},
};
export const actions = {
all: (api: GridApi<Row>) => api.collapseAll(),
log: (api: GridApi<Row>) => say(`Selected keys: ${api.getSelectedKeys().join(', ') || 'none'}`),
};