앞 칸이 같은 구간 안에서만 합치기Merge only inside the group to its left
'공통'이 여러 팀에 나와도 팀을 넘어서 합치지 않아요. 팀이 같은 구간 안에서만 합치고, 합친 칸을 고치면 묶음 전체에 한 번에 반영할 수도 있어요.A 'Shared' value that appears in several teams is merged only within each team. Editing a merged cell can also apply to the whole block.
코드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="within">
<option value="team">팀 안에서만</option>
<option value="all">값만 같으면</option>
</select>
<select aria-label="보이는 방식" id="shown">
<option value="merge">한 칸으로 합치기</option>
<option value="top">첫 줄에만 값 보이기</option>
</select>
<select aria-label="합친 칸을 고치면" id="editAll">
<option value="all">묶음 전체에 적용</option>
<option value="one">그 줄만 적용</option>
</select>
<button type="button" id="undo">되돌리기</button>
</div>
<div id="grid" style="height: 360px"></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('within').addEventListener('change', (event) => actions.within(api, event.target.value));
document.getElementById('shown').addEventListener('change', (event) => actions.shown(api, event.target.value));
document.getElementById('editAll').addEventListener('change', (event) => actions.editAll(api, event.target.value));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));// '공통'이 팀마다 나오지만, 서로 다른 팀의 '공통'까지 한 칸으로 합치면 헷갈려요.
// mergeWithin: 'team'을 주면 팀이 같은 구간 안에서만 합쳐요.
let within = true;
let shown = 'merge';
let editAll = true;
const columns = () => [
{ id: 'team', title: '팀', width: 100, merge: true },
{
id: 'scope',
title: '구분',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: '할 일', width: 200, editable: true },
];
// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word) => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0)
return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0; // 영 일 이 삼 사 오 육 칠 팔 구
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word) => (batchim(word) ? '을' : '를');
const euroRo = (word) => (batchim(word) && batchim(word) !== 8 ? '으로' : '로');
export const options = {
columns: columns(),
rows: [
{ id: 1, team: '기획', scope: '공통', task: '스프린트 계획 세우기' },
{ id: 2, team: '기획', scope: '공통', task: '백로그 점검하기' },
{ id: 3, team: '기획', scope: '공통', task: '로드맵 업데이트' },
{ id: 4, team: '디자인', scope: '공통', task: '데모 화면 준비' },
{ id: 5, team: '디자인', scope: '공통', task: '피드백 모으기' },
{ id: 6, team: '디자인', scope: '개별', task: '아이콘 정리하기' },
{ id: 7, team: '개발', scope: '개별', task: '쿼리 속도 개선' },
{ id: 8, team: '개발', scope: '개별', task: '인덱스 추가' },
{ id: 9, team: '개발', scope: '공통', task: '주간 보고서 작성' },
],
rowKey: 'id',
};
export const actions = {
within: (api, value) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api, value) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api, value) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api) => api.undo(),
};
export function setup(api, log) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (함께 바뀐 줄: ${event.alsoRowKeys.join(', ')})`
: '';
const alsoEn = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log({
ko: `${String(event.rowKey)}번 줄의 ${title}${eulReul(title)} "${String(event.newValue)}"${euroRo(String(event.newValue))} 바꿨어요${also}`,
en: `Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${alsoEn}`,
});
});
}<!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="within">
<option value="team">팀 안에서만</option>
<option value="all">값만 같으면</option>
</select>
<select aria-label="보이는 방식" id="shown">
<option value="merge">한 칸으로 합치기</option>
<option value="top">첫 줄에만 값 보이기</option>
</select>
<select aria-label="합친 칸을 고치면" id="editAll">
<option value="all">묶음 전체에 적용</option>
<option value="one">그 줄만 적용</option>
</select>
<button type="button" id="undo">되돌리기</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// '공통'이 팀마다 나오지만, 서로 다른 팀의 '공통'까지 한 칸으로 합치면 헷갈려요.
// mergeWithin: 'team'을 주면 팀이 같은 구간 안에서만 합쳐요.
let within = true;
let shown = 'merge';
let editAll = true;
const columns = () => [
{ id: 'team', title: '팀', width: 100, merge: true },
{
id: 'scope',
title: '구분',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: '할 일', width: 200, editable: true },
];
// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word) => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0)
return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0; // 영 일 이 삼 사 오 육 칠 팔 구
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word) => (batchim(word) ? '을' : '를');
const euroRo = (word) => (batchim(word) && batchim(word) !== 8 ? '으로' : '로');
const options = {
columns: columns(),
rows: [
{ id: 1, team: '기획', scope: '공통', task: '스프린트 계획 세우기' },
{ id: 2, team: '기획', scope: '공통', task: '백로그 점검하기' },
{ id: 3, team: '기획', scope: '공통', task: '로드맵 업데이트' },
{ id: 4, team: '디자인', scope: '공통', task: '데모 화면 준비' },
{ id: 5, team: '디자인', scope: '공통', task: '피드백 모으기' },
{ id: 6, team: '디자인', scope: '개별', task: '아이콘 정리하기' },
{ id: 7, team: '개발', scope: '개별', task: '쿼리 속도 개선' },
{ id: 8, team: '개발', scope: '개별', task: '인덱스 추가' },
{ id: 9, team: '개발', scope: '공통', task: '주간 보고서 작성' },
],
rowKey: 'id',
};
const actions = {
within: (api, value) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api, value) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api, value) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api) => api.undo(),
};
function setup(api, log) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (함께 바뀐 줄: ${event.alsoRowKeys.join(', ')})`
: '';
const alsoEn = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log({
ko: `${String(event.rowKey)}번 줄의 ${title}${eulReul(title)} "${String(event.newValue)}"${euroRo(String(event.newValue))} 바꿨어요${also}`,
en: `Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${alsoEn}`,
});
});
}
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('within').addEventListener('change', (event) => actions.within(api, event.target.value));
document.getElementById('shown').addEventListener('change', (event) => actions.shown(api, event.target.value));
document.getElementById('editAll').addEventListener('change', (event) => actions.editAll(api, event.target.value));
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">
<select
aria-label="합치는 기준"
disabled={!api}
onChange={(event) => api && actions.within(api, event.target.value)}
>
<option value="team">팀 안에서만</option>
<option value="all">값만 같으면</option>
</select>
<select
aria-label="보이는 방식"
disabled={!api}
onChange={(event) => api && actions.shown(api, event.target.value)}
>
<option value="merge">한 칸으로 합치기</option>
<option value="top">첫 줄에만 값 보이기</option>
</select>
<select
aria-label="합친 칸을 고치면"
disabled={!api}
onChange={(event) => api && actions.editAll(api, event.target.value)}
>
<option value="all">묶음 전체에 적용</option>
<option value="one">그 줄만 적용</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>되돌리기</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
scope: string;
task: string;
}
// '공통'이 팀마다 나오지만, 서로 다른 팀의 '공통'까지 한 칸으로 합치면 헷갈려요.
// mergeWithin: 'team'을 주면 팀이 같은 구간 안에서만 합쳐요.
let within = true;
let shown: 'merge' | 'top' = 'merge';
let editAll = true;
const columns = (): ColumnDef<Row>[] => [
{ id: 'team', title: '팀', width: 100, merge: true },
{
id: 'scope',
title: '구분',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: '할 일', width: 200, editable: true },
];
// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word: string): number => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0) return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0; // 영 일 이 삼 사 오 육 칠 팔 구
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word: string): string => (batchim(word) ? '을' : '를');
const euroRo = (word: string): string => (batchim(word) && batchim(word) !== 8 ? '으로' : '로');
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, team: '기획', scope: '공통', task: '스프린트 계획 세우기' },
{ id: 2, team: '기획', scope: '공통', task: '백로그 점검하기' },
{ id: 3, team: '기획', scope: '공통', task: '로드맵 업데이트' },
{ id: 4, team: '디자인', scope: '공통', task: '데모 화면 준비' },
{ id: 5, team: '디자인', scope: '공통', task: '피드백 모으기' },
{ id: 6, team: '디자인', scope: '개별', task: '아이콘 정리하기' },
{ id: 7, team: '개발', scope: '개별', task: '쿼리 속도 개선' },
{ id: 8, team: '개발', scope: '개별', task: '인덱스 추가' },
{ id: 9, team: '개발', scope: '공통', task: '주간 보고서 작성' },
],
rowKey: 'id',
};
export const actions = {
within: (api: GridApi<Row>, value?: string) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api: GridApi<Row>, value?: string) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api: GridApi<Row>, value?: string) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api: GridApi<Row>) => api.undo(),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (함께 바뀐 줄: ${event.alsoRowKeys.join(', ')})`
: '';
const alsoEn = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log({
ko: `${String(event.rowKey)}번 줄의 ${title}${eulReul(title)} "${String(event.newValue)}"${euroRo(String(event.newValue))} 바꿨어요${also}`,
en: `Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${alsoEn}`,
});
});
}버튼을 누르면 이 예제의 코드가 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.within(api, ($event.target as HTMLSelectElement).value)"
>
<option value="team">팀 안에서만</option>
<option value="all">값만 같으면</option>
</select>
<select
aria-label="보이는 방식"
:disabled="!api"
@change="api && actions.shown(api, ($event.target as HTMLSelectElement).value)"
>
<option value="merge">한 칸으로 합치기</option>
<option value="top">첫 줄에만 값 보이기</option>
</select>
<select
aria-label="합친 칸을 고치면"
:disabled="!api"
@change="api && actions.editAll(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all">묶음 전체에 적용</option>
<option value="one">그 줄만 적용</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.undo(api)">되돌리기</button>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
scope: string;
task: string;
}
// '공통'이 팀마다 나오지만, 서로 다른 팀의 '공통'까지 한 칸으로 합치면 헷갈려요.
// mergeWithin: 'team'을 주면 팀이 같은 구간 안에서만 합쳐요.
let within = true;
let shown: 'merge' | 'top' = 'merge';
let editAll = true;
const columns = (): ColumnDef<Row>[] => [
{ id: 'team', title: '팀', width: 100, merge: true },
{
id: 'scope',
title: '구분',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: '할 일', width: 200, editable: true },
];
// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word: string): number => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0) return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0; // 영 일 이 삼 사 오 육 칠 팔 구
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word: string): string => (batchim(word) ? '을' : '를');
const euroRo = (word: string): string => (batchim(word) && batchim(word) !== 8 ? '으로' : '로');
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, team: '기획', scope: '공통', task: '스프린트 계획 세우기' },
{ id: 2, team: '기획', scope: '공통', task: '백로그 점검하기' },
{ id: 3, team: '기획', scope: '공통', task: '로드맵 업데이트' },
{ id: 4, team: '디자인', scope: '공통', task: '데모 화면 준비' },
{ id: 5, team: '디자인', scope: '공통', task: '피드백 모으기' },
{ id: 6, team: '디자인', scope: '개별', task: '아이콘 정리하기' },
{ id: 7, team: '개발', scope: '개별', task: '쿼리 속도 개선' },
{ id: 8, team: '개발', scope: '개별', task: '인덱스 추가' },
{ id: 9, team: '개발', scope: '공통', task: '주간 보고서 작성' },
],
rowKey: 'id',
};
export const actions = {
within: (api: GridApi<Row>, value?: string) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api: GridApi<Row>, value?: string) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api: GridApi<Row>, value?: string) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api: GridApi<Row>) => api.undo(),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (함께 바뀐 줄: ${event.alsoRowKeys.join(', ')})`
: '';
const alsoEn = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log({
ko: `${String(event.rowKey)}번 줄의 ${title}${eulReul(title)} "${String(event.newValue)}"${euroRo(String(event.newValue))} 바꿨어요${also}`,
en: `Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${alsoEn}`,
});
});
}버튼을 누르면 이 예제의 코드가 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.within(api, $any($event.target).value)"
>
<option value="team">팀 안에서만</option>
<option value="all">값만 같으면</option>
</select>
<select
aria-label="보이는 방식"
[disabled]="!api"
(change)="api && actions.shown(api, $any($event.target).value)"
>
<option value="merge">한 칸으로 합치기</option>
<option value="top">첫 줄에만 값 보이기</option>
</select>
<select
aria-label="합친 칸을 고치면"
[disabled]="!api"
(change)="api && actions.editAll(api, $any($event.target).value)"
>
<option value="all">묶음 전체에 적용</option>
<option value="one">그 줄만 적용</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>되돌리기</button>
</div>
<mx-grid style="height: 360px" [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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
scope: string;
task: string;
}
// '공통'이 팀마다 나오지만, 서로 다른 팀의 '공통'까지 한 칸으로 합치면 헷갈려요.
// mergeWithin: 'team'을 주면 팀이 같은 구간 안에서만 합쳐요.
let within = true;
let shown: 'merge' | 'top' = 'merge';
let editAll = true;
const columns = (): ColumnDef<Row>[] => [
{ id: 'team', title: '팀', width: 100, merge: true },
{
id: 'scope',
title: '구분',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: '할 일', width: 200, editable: true },
];
// 데이터 값 뒤에 붙는 조사는 마지막 글자의 받침에 맞춰 골라요(숫자는 읽는 소리 기준).
const batchim = (word: string): number => {
const ch = word.trim().slice(-1);
const digit = '0123456789'.indexOf(ch);
if (digit >= 0) return [21, 8, 0, 16, 0, 0, 1, 8, 8, 0][digit] ?? 0; // 영 일 이 삼 사 오 육 칠 팔 구
const code = ch.charCodeAt(0) - 0xac00;
return code >= 0 && code <= 11171 ? code % 28 : 0;
};
const eulReul = (word: string): string => (batchim(word) ? '을' : '를');
const euroRo = (word: string): string => (batchim(word) && batchim(word) !== 8 ? '으로' : '로');
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, team: '기획', scope: '공통', task: '스프린트 계획 세우기' },
{ id: 2, team: '기획', scope: '공통', task: '백로그 점검하기' },
{ id: 3, team: '기획', scope: '공통', task: '로드맵 업데이트' },
{ id: 4, team: '디자인', scope: '공통', task: '데모 화면 준비' },
{ id: 5, team: '디자인', scope: '공통', task: '피드백 모으기' },
{ id: 6, team: '디자인', scope: '개별', task: '아이콘 정리하기' },
{ id: 7, team: '개발', scope: '개별', task: '쿼리 속도 개선' },
{ id: 8, team: '개발', scope: '개별', task: '인덱스 추가' },
{ id: 9, team: '개발', scope: '공통', task: '주간 보고서 작성' },
],
rowKey: 'id',
};
export const actions = {
within: (api: GridApi<Row>, value?: string) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api: GridApi<Row>, value?: string) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api: GridApi<Row>, value?: string) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api: GridApi<Row>) => api.undo(),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (함께 바뀐 줄: ${event.alsoRowKeys.join(', ')})`
: '';
const alsoEn = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log({
ko: `${String(event.rowKey)}번 줄의 ${title}${eulReul(title)} "${String(event.newValue)}"${euroRo(String(event.newValue))} 바꿨어요${also}`,
en: `Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${alsoEn}`,
});
});
}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="Merge rule" id="within">
<option value="team">Inside each team</option>
<option value="all">Equal value only</option>
</select>
<select aria-label="Display" id="shown">
<option value="merge">Merge cells</option>
<option value="top">First row only</option>
</select>
<select aria-label="Editing a merged cell" id="editAll">
<option value="all">Apply to the whole block</option>
<option value="one">Apply to that row only</option>
</select>
<button type="button" id="undo">Undo</button>
</div>
<div id="grid" style="height: 360px"></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('within').addEventListener('change', (event) => actions.within(api, event.target.value));
document.getElementById('shown').addEventListener('change', (event) => actions.shown(api, event.target.value));
document.getElementById('editAll').addEventListener('change', (event) => actions.editAll(api, event.target.value));
document.getElementById('undo').addEventListener('click', () => actions.undo(api));// 'Shared' shows up under every team, but merging 'Shared' across different teams into one cell is confusing.
// With mergeWithin: 'team', cells merge only inside a run of the same team.
let within = true;
let shown = 'merge';
let editAll = true;
const columns = () => [
{ id: 'team', title: 'Team', width: 100, merge: true },
{
id: 'scope',
title: 'Scope',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: 'Task', width: 220, editable: true },
];
export const options = {
columns: columns(),
rows: [
{ id: 1, team: 'Planning', scope: 'Shared', task: 'Plan the sprint' },
{ id: 2, team: 'Planning', scope: 'Shared', task: 'Review the backlog' },
{ id: 3, team: 'Planning', scope: 'Shared', task: 'Update the roadmap' },
{ id: 4, team: 'Design', scope: 'Shared', task: 'Prepare the demo screen' },
{ id: 5, team: 'Design', scope: 'Shared', task: 'Collect feedback' },
{ id: 6, team: 'Design', scope: 'Own', task: 'Tidy up the icons' },
{ id: 7, team: 'Dev', scope: 'Own', task: 'Speed up queries' },
{ id: 8, team: 'Dev', scope: 'Own', task: 'Add an index' },
{ id: 9, team: 'Dev', scope: 'Shared', task: 'Write the weekly report' },
],
rowKey: 'id',
};
export const actions = {
within: (api, value) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api, value) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api, value) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api) => api.undo(),
};
export function setup(api, log) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log(`Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${also}`);
});
}<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Merge only inside the group to its left</title>
</head>
<body>
<div class="toolbar">
<select aria-label="Merge rule" id="within">
<option value="team">Inside each team</option>
<option value="all">Equal value only</option>
</select>
<select aria-label="Display" id="shown">
<option value="merge">Merge cells</option>
<option value="top">First row only</option>
</select>
<select aria-label="Editing a merged cell" id="editAll">
<option value="all">Apply to the whole block</option>
<option value="one">Apply to that row only</option>
</select>
<button type="button" id="undo">Undo</button>
</div>
<div id="grid" style="height: 360px"></div>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script>
// 'Shared' shows up under every team, but merging 'Shared' across different teams into one cell is confusing.
// With mergeWithin: 'team', cells merge only inside a run of the same team.
let within = true;
let shown = 'merge';
let editAll = true;
const columns = () => [
{ id: 'team', title: 'Team', width: 100, merge: true },
{
id: 'scope',
title: 'Scope',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: 'Task', width: 220, editable: true },
];
const options = {
columns: columns(),
rows: [
{ id: 1, team: 'Planning', scope: 'Shared', task: 'Plan the sprint' },
{ id: 2, team: 'Planning', scope: 'Shared', task: 'Review the backlog' },
{ id: 3, team: 'Planning', scope: 'Shared', task: 'Update the roadmap' },
{ id: 4, team: 'Design', scope: 'Shared', task: 'Prepare the demo screen' },
{ id: 5, team: 'Design', scope: 'Shared', task: 'Collect feedback' },
{ id: 6, team: 'Design', scope: 'Own', task: 'Tidy up the icons' },
{ id: 7, team: 'Dev', scope: 'Own', task: 'Speed up queries' },
{ id: 8, team: 'Dev', scope: 'Own', task: 'Add an index' },
{ id: 9, team: 'Dev', scope: 'Shared', task: 'Write the weekly report' },
],
rowKey: 'id',
};
const actions = {
within: (api, value) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api, value) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api, value) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api) => api.undo(),
};
function setup(api, log) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log(`Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${also}`);
});
}
options.ariaLabel = "Merge only inside the group to its left";
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('within').addEventListener('change', (event) => actions.within(api, event.target.value));
document.getElementById('shown').addEventListener('change', (event) => actions.shown(api, event.target.value));
document.getElementById('editAll').addEventListener('change', (event) => actions.editAll(api, event.target.value));
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">
<select
aria-label="Merge rule"
disabled={!api}
onChange={(event) => api && actions.within(api, event.target.value)}
>
<option value="team">Inside each team</option>
<option value="all">Equal value only</option>
</select>
<select
aria-label="Display"
disabled={!api}
onChange={(event) => api && actions.shown(api, event.target.value)}
>
<option value="merge">Merge cells</option>
<option value="top">First row only</option>
</select>
<select
aria-label="Editing a merged cell"
disabled={!api}
onChange={(event) => api && actions.editAll(api, event.target.value)}
>
<option value="all">Apply to the whole block</option>
<option value="one">Apply to that row only</option>
</select>
<button
type="button"
disabled={!api}
onClick={() => api && actions.undo(api)}
>Undo</button>
</div>
<Grid style={{ height: 360 }} ref={gridRef} options={options} />
</>
);
}import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
scope: string;
task: string;
}
// 'Shared' shows up under every team, but merging 'Shared' across different teams into one cell is confusing.
// With mergeWithin: 'team', cells merge only inside a run of the same team.
let within = true;
let shown: 'merge' | 'top' = 'merge';
let editAll = true;
const columns = (): ColumnDef<Row>[] => [
{ id: 'team', title: 'Team', width: 100, merge: true },
{
id: 'scope',
title: 'Scope',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: 'Task', width: 220, editable: true },
];
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, team: 'Planning', scope: 'Shared', task: 'Plan the sprint' },
{ id: 2, team: 'Planning', scope: 'Shared', task: 'Review the backlog' },
{ id: 3, team: 'Planning', scope: 'Shared', task: 'Update the roadmap' },
{ id: 4, team: 'Design', scope: 'Shared', task: 'Prepare the demo screen' },
{ id: 5, team: 'Design', scope: 'Shared', task: 'Collect feedback' },
{ id: 6, team: 'Design', scope: 'Own', task: 'Tidy up the icons' },
{ id: 7, team: 'Dev', scope: 'Own', task: 'Speed up queries' },
{ id: 8, team: 'Dev', scope: 'Own', task: 'Add an index' },
{ id: 9, team: 'Dev', scope: 'Shared', task: 'Write the weekly report' },
],
rowKey: 'id',
};
export const actions = {
within: (api: GridApi<Row>, value?: string) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api: GridApi<Row>, value?: string) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api: GridApi<Row>, value?: string) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api: GridApi<Row>) => api.undo(),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log(`Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${also}`);
});
}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="Merge rule"
:disabled="!api"
@change="api && actions.within(api, ($event.target as HTMLSelectElement).value)"
>
<option value="team">Inside each team</option>
<option value="all">Equal value only</option>
</select>
<select
aria-label="Display"
:disabled="!api"
@change="api && actions.shown(api, ($event.target as HTMLSelectElement).value)"
>
<option value="merge">Merge cells</option>
<option value="top">First row only</option>
</select>
<select
aria-label="Editing a merged cell"
:disabled="!api"
@change="api && actions.editAll(api, ($event.target as HTMLSelectElement).value)"
>
<option value="all">Apply to the whole block</option>
<option value="one">Apply to that row only</option>
</select>
<button type="button" :disabled="!api" @click="api && actions.undo(api)">Undo</button>
</div>
<Grid style="height: 360px" :options="options" @ready="onReady" />
</template>import type { ColumnDef, GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
scope: string;
task: string;
}
// 'Shared' shows up under every team, but merging 'Shared' across different teams into one cell is confusing.
// With mergeWithin: 'team', cells merge only inside a run of the same team.
let within = true;
let shown: 'merge' | 'top' = 'merge';
let editAll = true;
const columns = (): ColumnDef<Row>[] => [
{ id: 'team', title: 'Team', width: 100, merge: true },
{
id: 'scope',
title: 'Scope',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: 'Task', width: 220, editable: true },
];
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, team: 'Planning', scope: 'Shared', task: 'Plan the sprint' },
{ id: 2, team: 'Planning', scope: 'Shared', task: 'Review the backlog' },
{ id: 3, team: 'Planning', scope: 'Shared', task: 'Update the roadmap' },
{ id: 4, team: 'Design', scope: 'Shared', task: 'Prepare the demo screen' },
{ id: 5, team: 'Design', scope: 'Shared', task: 'Collect feedback' },
{ id: 6, team: 'Design', scope: 'Own', task: 'Tidy up the icons' },
{ id: 7, team: 'Dev', scope: 'Own', task: 'Speed up queries' },
{ id: 8, team: 'Dev', scope: 'Own', task: 'Add an index' },
{ id: 9, team: 'Dev', scope: 'Shared', task: 'Write the weekly report' },
],
rowKey: 'id',
};
export const actions = {
within: (api: GridApi<Row>, value?: string) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api: GridApi<Row>, value?: string) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api: GridApi<Row>, value?: string) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api: GridApi<Row>) => api.undo(),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log(`Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${also}`);
});
}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="Merge rule"
[disabled]="!api"
(change)="api && actions.within(api, $any($event.target).value)"
>
<option value="team">Inside each team</option>
<option value="all">Equal value only</option>
</select>
<select
aria-label="Display"
[disabled]="!api"
(change)="api && actions.shown(api, $any($event.target).value)"
>
<option value="merge">Merge cells</option>
<option value="top">First row only</option>
</select>
<select
aria-label="Editing a merged cell"
[disabled]="!api"
(change)="api && actions.editAll(api, $any($event.target).value)"
>
<option value="all">Apply to the whole block</option>
<option value="one">Apply to that row only</option>
</select>
<button
type="button"
[disabled]="!api"
(click)="api && actions.undo(api)"
>Undo</button>
</div>
<mx-grid style="height: 360px" [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 { ColumnDef, GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
team: string;
scope: string;
task: string;
}
// 'Shared' shows up under every team, but merging 'Shared' across different teams into one cell is confusing.
// With mergeWithin: 'team', cells merge only inside a run of the same team.
let within = true;
let shown: 'merge' | 'top' = 'merge';
let editAll = true;
const columns = (): ColumnDef<Row>[] => [
{ id: 'team', title: 'Team', width: 100, merge: true },
{
id: 'scope',
title: 'Scope',
width: 100,
merge: shown === 'top' ? 'top' : true,
editable: true,
mergeEditAll: editAll,
...(within ? { mergeWithin: 'team' } : {}),
},
{ id: 'task', title: 'Task', width: 220, editable: true },
];
export const options: GridOptions<Row> = {
columns: columns(),
rows: [
{ id: 1, team: 'Planning', scope: 'Shared', task: 'Plan the sprint' },
{ id: 2, team: 'Planning', scope: 'Shared', task: 'Review the backlog' },
{ id: 3, team: 'Planning', scope: 'Shared', task: 'Update the roadmap' },
{ id: 4, team: 'Design', scope: 'Shared', task: 'Prepare the demo screen' },
{ id: 5, team: 'Design', scope: 'Shared', task: 'Collect feedback' },
{ id: 6, team: 'Design', scope: 'Own', task: 'Tidy up the icons' },
{ id: 7, team: 'Dev', scope: 'Own', task: 'Speed up queries' },
{ id: 8, team: 'Dev', scope: 'Own', task: 'Add an index' },
{ id: 9, team: 'Dev', scope: 'Shared', task: 'Write the weekly report' },
],
rowKey: 'id',
};
export const actions = {
within: (api: GridApi<Row>, value?: string) => {
within = value !== 'all';
api.setColumns(columns());
},
shown: (api: GridApi<Row>, value?: string) => {
shown = value === 'top' ? 'top' : 'merge';
api.setColumns(columns());
},
editAll: (api: GridApi<Row>, value?: string) => {
editAll = value !== 'one';
api.setColumns(columns());
},
undo: (api: GridApi<Row>) => api.undo(),
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
return api.on('editCommitted', (event) => {
const also = event.alsoRowKeys?.length
? ` (also changed: ${event.alsoRowKeys.join(', ')})`
: '';
const title = api.getColumns().find((c) => c.id === event.columnId)?.title ?? event.columnId;
log(`Row ${String(event.rowKey)}: ${title} set to "${String(event.newValue)}"${also}`);
});
}