그룹 행에서 팀 전체 값 한 번에 바꾸기Change a whole group's value from its group row
groupRows.editable에 컬럼을 적으면 그룹 행의 그 칸을 두 번 눌러 그 그룹 모든 행의 값을 한 번에 바꿔요. 되돌리기는 한 단계이고, 자식 행 하나라도 검증·훅에 걸리면 아무것도 바뀌지 않아요.List columns in groupRows.editable and a double-click on that cell of a group row sets the value on every row of the group at once. Undo is one step, and if any child fails validation or a hook nothing changes.
코드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="allSenior">전원 시니어(코드)</button>
<button type="button" id="undo">되돌리기</button>
</div>
<div id="grid" style="height: 330px"></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('allSenior').addEventListener('click', () => actions.allSenior(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업'];
const levels = ['주니어', '미드', '시니어'];
const rows = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)],
level: levels[i % 3],
note: '',
hours: 30 + ((i * 5) % 14),
}));
// groupRows.editable에 컬럼 id를 적으면 그룹 행의 그 칸을 두 번 눌러 고칠 수 있어요. 값은 그 그룹의 모든 자식 행에 한 번에 들어가고(되돌리기 한 단계),
// 자식마다 편집 가능·beforeEdit·검증을 먼저 보고 하나라도 걸리면 아무것도 바뀌지 않아요. 집계가 있는 칸(주간 시간)은 고칠 수 없어요.
export const options = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 90 },
{
id: 'level',
title: '등급',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: '메모',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
export function setup(api, log) {
log({
ko: '그룹 행의 "등급"·"메모" 칸을 두 번 누르면 그 팀 전원의 값이 한 번에 바뀌어요.',
en: 'Double-click the Level or Note cell of a group row to change it for the whole team at once.',
});
const offs = [
api.on('groupRowEdited', (e) => log({
ko: `✓ ${e.keys.length}명의 ${e.columnId}을(를) "${String(e.value)}"(으)로 바꿨어요`,
en: `✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`,
})),
api.on('validationFailed', (e) => log({ ko: `✗ ${e.rowKey}번: ${e.message}`, en: `✗ ${e.rowKey}: ${e.message}` })),
];
return () => offs.forEach((off) => off());
}
export const actions = {
allSenior: (api) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group')
api.editGroupRow(first.key, 'level', '시니어');
},
undo: (api) => api.undo(),
};<!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="allSenior">전원 시니어(코드)</button>
<button type="button" id="undo">되돌리기</button>
</div>
<div id="grid" style="height: 330px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업'];
const levels = ['주니어', '미드', '시니어'];
const rows = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)],
level: levels[i % 3],
note: '',
hours: 30 + ((i * 5) % 14),
}));
// groupRows.editable에 컬럼 id를 적으면 그룹 행의 그 칸을 두 번 눌러 고칠 수 있어요. 값은 그 그룹의 모든 자식 행에 한 번에 들어가고(되돌리기 한 단계),
// 자식마다 편집 가능·beforeEdit·검증을 먼저 보고 하나라도 걸리면 아무것도 바뀌지 않아요. 집계가 있는 칸(주간 시간)은 고칠 수 없어요.
const options = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 90 },
{
id: 'level',
title: '등급',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: '메모',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
function setup(api, log) {
log({
ko: '그룹 행의 "등급"·"메모" 칸을 두 번 누르면 그 팀 전원의 값이 한 번에 바뀌어요.',
en: 'Double-click the Level or Note cell of a group row to change it for the whole team at once.',
});
const offs = [
api.on('groupRowEdited', (e) => log({
ko: `✓ ${e.keys.length}명의 ${e.columnId}을(를) "${String(e.value)}"(으)로 바꿨어요`,
en: `✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`,
})),
api.on('validationFailed', (e) => log({ ko: `✗ ${e.rowKey}번: ${e.message}`, en: `✗ ${e.rowKey}: ${e.message}` })),
];
return () => offs.forEach((off) => off());
}
const actions = {
allSenior: (api) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group')
api.editGroupRow(first.key, 'level', '시니어');
},
undo: (api) => api.undo(),
};
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('allSenior').addEventListener('click', () => actions.allSenior(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(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.allSenior(api)}
>전원 시니어(코드)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>되돌리기</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
name: string;
team: string;
level: string;
note: string;
hours: number;
}
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업'];
const levels = ['주니어', '미드', '시니어'];
const rows: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)] as string,
level: levels[i % 3] as string,
note: '',
hours: 30 + ((i * 5) % 14),
}));
// groupRows.editable에 컬럼 id를 적으면 그룹 행의 그 칸을 두 번 눌러 고칠 수 있어요. 값은 그 그룹의 모든 자식 행에 한 번에 들어가고(되돌리기 한 단계),
// 자식마다 편집 가능·beforeEdit·검증을 먼저 보고 하나라도 걸리면 아무것도 바뀌지 않아요. 집계가 있는 칸(주간 시간)은 고칠 수 없어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 90 },
{
id: 'level',
title: '등급',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: '메모',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '그룹 행의 "등급"·"메모" 칸을 두 번 누르면 그 팀 전원의 값이 한 번에 바뀌어요.',
en: 'Double-click the Level or Note cell of a group row to change it for the whole team at once.',
});
const offs = [
api.on('groupRowEdited', (e) =>
log({
ko: `✓ ${e.keys.length}명의 ${e.columnId}을(를) "${String(e.value)}"(으)로 바꿨어요`,
en: `✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`,
}),
),
api.on('validationFailed', (e) =>
log({ ko: `✗ ${e.rowKey}번: ${e.message}`, en: `✗ ${e.rowKey}: ${e.message}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
allSenior: (api: GridApi<Row>) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group') api.editGroupRow(first.key, 'level', '시니어');
},
undo: (api: GridApi<Row>) => api.undo(),
};버튼을 누르면 이 예제의 코드가 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.allSenior(api)"
>전원 시니어(코드)</button>
<button type="button" :disabled="!api" @click="api && actions.undo(api)">되돌리기</button>
</div>
<Grid style="height: 330px" :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;
name: string;
team: string;
level: string;
note: string;
hours: number;
}
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업'];
const levels = ['주니어', '미드', '시니어'];
const rows: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)] as string,
level: levels[i % 3] as string,
note: '',
hours: 30 + ((i * 5) % 14),
}));
// groupRows.editable에 컬럼 id를 적으면 그룹 행의 그 칸을 두 번 눌러 고칠 수 있어요. 값은 그 그룹의 모든 자식 행에 한 번에 들어가고(되돌리기 한 단계),
// 자식마다 편집 가능·beforeEdit·검증을 먼저 보고 하나라도 걸리면 아무것도 바뀌지 않아요. 집계가 있는 칸(주간 시간)은 고칠 수 없어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 90 },
{
id: 'level',
title: '등급',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: '메모',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '그룹 행의 "등급"·"메모" 칸을 두 번 누르면 그 팀 전원의 값이 한 번에 바뀌어요.',
en: 'Double-click the Level or Note cell of a group row to change it for the whole team at once.',
});
const offs = [
api.on('groupRowEdited', (e) =>
log({
ko: `✓ ${e.keys.length}명의 ${e.columnId}을(를) "${String(e.value)}"(으)로 바꿨어요`,
en: `✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`,
}),
),
api.on('validationFailed', (e) =>
log({ ko: `✗ ${e.rowKey}번: ${e.message}`, en: `✗ ${e.rowKey}: ${e.message}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
allSenior: (api: GridApi<Row>) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group') api.editGroupRow(first.key, 'level', '시니어');
},
undo: (api: GridApi<Row>) => api.undo(),
};버튼을 누르면 이 예제의 코드가 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.allSenior(api)"
>전원 시니어(코드)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>되돌리기</button>
</div>
<mx-grid style="height: 330px" [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;
name: string;
team: string;
level: string;
note: string;
hours: number;
}
const names = ['김서연', '이준호', '박민지', '최도윤', '정하은', '강지후', '윤서아', '임태민'];
const teams = ['개발', '디자인', '영업'];
const levels = ['주니어', '미드', '시니어'];
const rows: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)] as string,
level: levels[i % 3] as string,
note: '',
hours: 30 + ((i * 5) % 14),
}));
// groupRows.editable에 컬럼 id를 적으면 그룹 행의 그 칸을 두 번 눌러 고칠 수 있어요. 값은 그 그룹의 모든 자식 행에 한 번에 들어가고(되돌리기 한 단계),
// 자식마다 편집 가능·beforeEdit·검증을 먼저 보고 하나라도 걸리면 아무것도 바뀌지 않아요. 집계가 있는 칸(주간 시간)은 고칠 수 없어요.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: '이름', width: 150 },
{ id: 'team', title: '팀', width: 90 },
{
id: 'level',
title: '등급',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: '메모',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: '주간 시간',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log({
ko: '그룹 행의 "등급"·"메모" 칸을 두 번 누르면 그 팀 전원의 값이 한 번에 바뀌어요.',
en: 'Double-click the Level or Note cell of a group row to change it for the whole team at once.',
});
const offs = [
api.on('groupRowEdited', (e) =>
log({
ko: `✓ ${e.keys.length}명의 ${e.columnId}을(를) "${String(e.value)}"(으)로 바꿨어요`,
en: `✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`,
}),
),
api.on('validationFailed', (e) =>
log({ ko: `✗ ${e.rowKey}번: ${e.message}`, en: `✗ ${e.rowKey}: ${e.message}` }),
),
];
return () => offs.forEach((off) => off());
}
export const actions = {
allSenior: (api: GridApi<Row>) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group') api.editGroupRow(first.key, 'level', '시니어');
},
undo: (api: GridApi<Row>) => api.undo(),
};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="allSenior">Everyone Senior (code)</button>
<button type="button" id="undo">Undo</button>
</div>
<div id="grid" style="height: 330px"></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('allSenior').addEventListener('click', () => actions.allSenior(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
];
const teams = ['Dev', 'Design', 'Sales'];
const levels = ['Junior', 'Mid', 'Senior'];
const rows = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)],
level: levels[i % 3],
note: '',
hours: 30 + ((i * 5) % 14),
}));
// Listing column ids in groupRows.editable lets users double-click that cell on a group row. The value goes to every child row at once (one undo step);
// each child is checked for editability, beforeEdit and validation first and a single failure changes nothing. Cells with an aggregate (weekly hours) cannot be edited.
export const options = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 90 },
{
id: 'level',
title: 'Level',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: 'Note',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
export function setup(api, log) {
log('Double-click the Level or Note cell of a group row to change it for the whole team at once.');
const offs = [
api.on('groupRowEdited', (e) => log(`✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`)),
api.on('validationFailed', (e) => log(`✗ ${e.rowKey}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
allSenior: (api) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group')
api.editGroupRow(first.key, 'level', 'Senior');
},
undo: (api) => api.undo(),
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Change a whole group's value from its group row</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="allSenior">Everyone Senior (code)</button>
<button type="button" id="undo">Undo</button>
</div>
<div id="grid" style="height: 330px"></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 Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
];
const teams = ['Dev', 'Design', 'Sales'];
const levels = ['Junior', 'Mid', 'Senior'];
const rows = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)],
level: levels[i % 3],
note: '',
hours: 30 + ((i * 5) % 14),
}));
// Listing column ids in groupRows.editable lets users double-click that cell on a group row. The value goes to every child row at once (one undo step);
// each child is checked for editability, beforeEdit and validation first and a single failure changes nothing. Cells with an aggregate (weekly hours) cannot be edited.
const options = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 90 },
{
id: 'level',
title: 'Level',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: 'Note',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
function setup(api, log) {
log('Double-click the Level or Note cell of a group row to change it for the whole team at once.');
const offs = [
api.on('groupRowEdited', (e) => log(`✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`)),
api.on('validationFailed', (e) => log(`✗ ${e.rowKey}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
const actions = {
allSenior: (api) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group')
api.editGroupRow(first.key, 'level', 'Senior');
},
undo: (api) => api.undo(),
};
options.ariaLabel = "Change a whole group's value from its group row";
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('allSenior').addEventListener('click', () => actions.allSenior(api));
document.getElementById('undo').addEventListener('click', () => actions.undo(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.allSenior(api)}
>Everyone Senior (code)</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>Undo</button>
</div>
<Grid style={{ height: 330 }} ref={gridRef} options={options} />
</>
);
}import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
level: string;
note: string;
hours: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
];
const teams = ['Dev', 'Design', 'Sales'];
const levels = ['Junior', 'Mid', 'Senior'];
const rows: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)] as string,
level: levels[i % 3] as string,
note: '',
hours: 30 + ((i * 5) % 14),
}));
// Listing column ids in groupRows.editable lets users double-click that cell on a group row. The value goes to every child row at once (one undo step);
// each child is checked for editability, beforeEdit and validation first and a single failure changes nothing. Cells with an aggregate (weekly hours) cannot be edited.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 90 },
{
id: 'level',
title: 'Level',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: 'Note',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click the Level or Note cell of a group row to change it for the whole team at once.',
);
const offs = [
api.on('groupRowEdited', (e) =>
log(`✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`),
),
api.on('validationFailed', (e) => log(`✗ ${e.rowKey}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
allSenior: (api: GridApi<Row>) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group') api.editGroupRow(first.key, 'level', 'Senior');
},
undo: (api: GridApi<Row>) => api.undo(),
};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.allSenior(api)"
>Everyone Senior (code)</button>
<button type="button" :disabled="!api" @click="api && actions.undo(api)">Undo</button>
</div>
<Grid style="height: 330px" :options="options" @ready="onReady" />
</template>import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
level: string;
note: string;
hours: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
];
const teams = ['Dev', 'Design', 'Sales'];
const levels = ['Junior', 'Mid', 'Senior'];
const rows: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)] as string,
level: levels[i % 3] as string,
note: '',
hours: 30 + ((i * 5) % 14),
}));
// Listing column ids in groupRows.editable lets users double-click that cell on a group row. The value goes to every child row at once (one undo step);
// each child is checked for editability, beforeEdit and validation first and a single failure changes nothing. Cells with an aggregate (weekly hours) cannot be edited.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 90 },
{
id: 'level',
title: 'Level',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: 'Note',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click the Level or Note cell of a group row to change it for the whole team at once.',
);
const offs = [
api.on('groupRowEdited', (e) =>
log(`✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`),
),
api.on('validationFailed', (e) => log(`✗ ${e.rowKey}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
allSenior: (api: GridApi<Row>) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group') api.editGroupRow(first.key, 'level', 'Senior');
},
undo: (api: GridApi<Row>) => api.undo(),
};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.allSenior(api)"
>Everyone Senior (code)</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>Undo</button>
</div>
<mx-grid style="height: 330px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
name: string;
team: string;
level: string;
note: string;
hours: number;
}
const names = [
'Liam Carter',
'Emma Stone',
'Noah Kim',
'Olivia Reed',
'Ava Brooks',
'Mason Lee',
'Sophia Hall',
'Lucas Wood',
];
const teams = ['Dev', 'Design', 'Sales'];
const levels = ['Junior', 'Mid', 'Senior'];
const rows: Row[] = Array.from({ length: 24 }, (_, i) => ({
id: i + 1,
name: `${names[i % names.length]} ${Math.floor(i / names.length) + 1}`,
team: teams[Math.floor(i / 8)] as string,
level: levels[i % 3] as string,
note: '',
hours: 30 + ((i * 5) % 14),
}));
// Listing column ids in groupRows.editable lets users double-click that cell on a group row. The value goes to every child row at once (one undo step);
// each child is checked for editability, beforeEdit and validation first and a single failure changes nothing. Cells with an aggregate (weekly hours) cannot be edited.
export const options: GridOptions<Row> = {
columns: [
{ id: 'name', title: 'Name', width: 150 },
{ id: 'team', title: 'Team', width: 90 },
{
id: 'level',
title: 'Level',
kind: 'select',
width: 110,
editable: true,
editorOptions: levels.map((value) => ({ value })),
},
{
id: 'note',
title: 'Note',
width: 160,
editable: true,
validation: { maxLength: 12 },
},
{
id: 'hours',
title: 'Weekly hours',
kind: 'number',
width: 130,
align: 'end',
editable: true,
aggregate: 'sum',
},
],
rows,
rowKey: 'id',
grouping: { by: ['team'], expandDepth: 1 },
groupRows: { editable: ['level', 'note'] },
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
log(
'Double-click the Level or Note cell of a group row to change it for the whole team at once.',
);
const offs = [
api.on('groupRowEdited', (e) =>
log(`✓ Set ${e.columnId} to "${String(e.value)}" for ${e.keys.length} people`),
),
api.on('validationFailed', (e) => log(`✗ ${e.rowKey}: ${e.message}`)),
];
return () => offs.forEach((off) => off());
}
export const actions = {
allSenior: (api: GridApi<Row>) => {
const first = api.getDisplayRow(0);
if (first?.kind === 'group') api.editGroupRow(first.key, 'level', 'Senior');
},
undo: (api: GridApi<Row>) => api.undo(),
};