합친 칸의 복사 글자 정하기Choose the copy text of merged cells
컬럼의 mergeCopy는 세로로 합친 구간을 복사할 때의 글자를 정해요. 'all'은 칸마다 자기 글자(기본), 'first'는 구간의 첫 줄만 쓰고 덮인 줄은 빈 글자, 'repeat'는 첫 줄 글자를 모든 줄에 반복해요. 'first'로 복사한 글자를 붙여넣을 때 덮인 줄의 빈 글자는 값을 지우지 않아요.The mergeCopy of a column sets the text used when a vertically merged span is copied. 'all' copies each cell's own text (default), 'first' writes only the first row and leaves the covered rows empty, and 'repeat' repeats the first row's text on every row. When text copied with 'first' is pasted back, an empty text on a covered row does not clear its value.
코드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="first">first</button>
<button type="button" id="all">all</button>
<button type="button" id="repeat">repeat</button>
<button type="button" id="copy">전체 복사</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('first').addEventListener('click', () => actions.first(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('repeat').addEventListener('click', () => actions.repeat(api));
document.getElementById('copy').addEventListener('click', () => actions.copy(api));const rows = [
{ id: 1, dept: '개발', team: '웹', name: '김하늘' },
{ id: 2, dept: '개발', team: '웹', name: '이도윤' },
{ id: 3, dept: '개발', team: '앱', name: '박서연' },
{ id: 4, dept: '운영', team: '인프라', name: '최지우' },
{ id: 5, dept: '디자인', team: '브랜드', name: '정민준' },
{ id: 6, dept: '디자인', team: '브랜드', name: '강서윤' },
];
// mergeCopy: 세로로 합친 구간을 복사할 때의 글자. 'all'(기본) 칸마다 자기 글자, 'first' 첫 줄만, 'repeat' 첫 줄 글자를 모든 줄에.
let mode = 'first';
export const options = {
columns: [
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say = () => { };
export function setup(_api, log) {
say = log;
log({
ko: '"부서" 열이 합쳐져 있어요. 버튼으로 복사 방식을 바꾼 뒤 "전체 복사"를 눌러 복사된 글자를 확인하세요.',
en: 'The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.',
});
}
function setMode(api, next) {
mode = next;
api.setColumns([
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
]);
say({ ko: `mergeCopy를 '${next}'로 바꿨어요.`, en: `mergeCopy is now '${next}'.` });
}
export const actions = {
all: (api) => setMode(api, 'all'),
first: (api) => setMode(api, 'first'),
repeat: (api) => setMode(api, 'repeat'),
copy: (api) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse())
say(line.replace(/\t/g, ' | '));
say({
ko: `mergeCopy '${mode}'로 복사한 글자예요(위에서 아래 순서).`,
en: `Text copied with mergeCopy '${mode}' (top to bottom).`,
});
},
};<!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="first">first</button>
<button type="button" id="all">all</button>
<button type="button" id="repeat">repeat</button>
<button type="button" id="copy">전체 복사</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 rows = [
{ id: 1, dept: '개발', team: '웹', name: '김하늘' },
{ id: 2, dept: '개발', team: '웹', name: '이도윤' },
{ id: 3, dept: '개발', team: '앱', name: '박서연' },
{ id: 4, dept: '운영', team: '인프라', name: '최지우' },
{ id: 5, dept: '디자인', team: '브랜드', name: '정민준' },
{ id: 6, dept: '디자인', team: '브랜드', name: '강서윤' },
];
// mergeCopy: 세로로 합친 구간을 복사할 때의 글자. 'all'(기본) 칸마다 자기 글자, 'first' 첫 줄만, 'repeat' 첫 줄 글자를 모든 줄에.
let mode = 'first';
const options = {
columns: [
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say = () => { };
function setup(_api, log) {
say = log;
log({
ko: '"부서" 열이 합쳐져 있어요. 버튼으로 복사 방식을 바꾼 뒤 "전체 복사"를 눌러 복사된 글자를 확인하세요.',
en: 'The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.',
});
}
function setMode(api, next) {
mode = next;
api.setColumns([
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
]);
say({ ko: `mergeCopy를 '${next}'로 바꿨어요.`, en: `mergeCopy is now '${next}'.` });
}
const actions = {
all: (api) => setMode(api, 'all'),
first: (api) => setMode(api, 'first'),
repeat: (api) => setMode(api, 'repeat'),
copy: (api) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse())
say(line.replace(/\t/g, ' | '));
say({
ko: `mergeCopy '${mode}'로 복사한 글자예요(위에서 아래 순서).`,
en: `Text copied with mergeCopy '${mode}' (top to bottom).`,
});
},
};
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('first').addEventListener('click', () => actions.first(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('repeat').addEventListener('click', () => actions.repeat(api));
document.getElementById('copy').addEventListener('click', () => actions.copy(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.first(api)}
>first</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.repeat(api)}
>repeat</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.copy(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;
dept: string;
team: string;
name: string;
}
const rows: Row[] = [
{ id: 1, dept: '개발', team: '웹', name: '김하늘' },
{ id: 2, dept: '개발', team: '웹', name: '이도윤' },
{ id: 3, dept: '개발', team: '앱', name: '박서연' },
{ id: 4, dept: '운영', team: '인프라', name: '최지우' },
{ id: 5, dept: '디자인', team: '브랜드', name: '정민준' },
{ id: 6, dept: '디자인', team: '브랜드', name: '강서윤' },
];
// mergeCopy: 세로로 합친 구간을 복사할 때의 글자. 'all'(기본) 칸마다 자기 글자, 'first' 첫 줄만, 'repeat' 첫 줄 글자를 모든 줄에.
let mode: 'all' | 'first' | 'repeat' = 'first';
export const options: GridOptions<Row> = {
columns: [
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '"부서" 열이 합쳐져 있어요. 버튼으로 복사 방식을 바꾼 뒤 "전체 복사"를 눌러 복사된 글자를 확인하세요.',
en: 'The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.',
});
}
function setMode(api: GridApi<Row>, next: typeof mode): void {
mode = next;
api.setColumns([
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
]);
say({ ko: `mergeCopy를 '${next}'로 바꿨어요.`, en: `mergeCopy is now '${next}'.` });
}
export const actions = {
all: (api: GridApi<Row>) => setMode(api, 'all'),
first: (api: GridApi<Row>) => setMode(api, 'first'),
repeat: (api: GridApi<Row>) => setMode(api, 'repeat'),
copy: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse()) say(line.replace(/\t/g, ' | '));
say({
ko: `mergeCopy '${mode}'로 복사한 글자예요(위에서 아래 순서).`,
en: `Text copied with mergeCopy '${mode}' (top to bottom).`,
});
},
};버튼을 누르면 이 예제의 코드가 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.first(api)">first</button>
<button type="button" :disabled="!api" @click="api && actions.all(api)">all</button>
<button type="button" :disabled="!api" @click="api && actions.repeat(api)">repeat</button>
<button type="button" :disabled="!api" @click="api && actions.copy(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;
dept: string;
team: string;
name: string;
}
const rows: Row[] = [
{ id: 1, dept: '개발', team: '웹', name: '김하늘' },
{ id: 2, dept: '개발', team: '웹', name: '이도윤' },
{ id: 3, dept: '개발', team: '앱', name: '박서연' },
{ id: 4, dept: '운영', team: '인프라', name: '최지우' },
{ id: 5, dept: '디자인', team: '브랜드', name: '정민준' },
{ id: 6, dept: '디자인', team: '브랜드', name: '강서윤' },
];
// mergeCopy: 세로로 합친 구간을 복사할 때의 글자. 'all'(기본) 칸마다 자기 글자, 'first' 첫 줄만, 'repeat' 첫 줄 글자를 모든 줄에.
let mode: 'all' | 'first' | 'repeat' = 'first';
export const options: GridOptions<Row> = {
columns: [
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '"부서" 열이 합쳐져 있어요. 버튼으로 복사 방식을 바꾼 뒤 "전체 복사"를 눌러 복사된 글자를 확인하세요.',
en: 'The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.',
});
}
function setMode(api: GridApi<Row>, next: typeof mode): void {
mode = next;
api.setColumns([
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
]);
say({ ko: `mergeCopy를 '${next}'로 바꿨어요.`, en: `mergeCopy is now '${next}'.` });
}
export const actions = {
all: (api: GridApi<Row>) => setMode(api, 'all'),
first: (api: GridApi<Row>) => setMode(api, 'first'),
repeat: (api: GridApi<Row>) => setMode(api, 'repeat'),
copy: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse()) say(line.replace(/\t/g, ' | '));
say({
ko: `mergeCopy '${mode}'로 복사한 글자예요(위에서 아래 순서).`,
en: `Text copied with mergeCopy '${mode}' (top to bottom).`,
});
},
};버튼을 누르면 이 예제의 코드가 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.first(api)"
>first</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.repeat(api)"
>repeat</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.copy(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;
dept: string;
team: string;
name: string;
}
const rows: Row[] = [
{ id: 1, dept: '개발', team: '웹', name: '김하늘' },
{ id: 2, dept: '개발', team: '웹', name: '이도윤' },
{ id: 3, dept: '개발', team: '앱', name: '박서연' },
{ id: 4, dept: '운영', team: '인프라', name: '최지우' },
{ id: 5, dept: '디자인', team: '브랜드', name: '정민준' },
{ id: 6, dept: '디자인', team: '브랜드', name: '강서윤' },
];
// mergeCopy: 세로로 합친 구간을 복사할 때의 글자. 'all'(기본) 칸마다 자기 글자, 'first' 첫 줄만, 'repeat' 첫 줄 글자를 모든 줄에.
let mode: 'all' | 'first' | 'repeat' = 'first';
export const options: GridOptions<Row> = {
columns: [
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log({
ko: '"부서" 열이 합쳐져 있어요. 버튼으로 복사 방식을 바꾼 뒤 "전체 복사"를 눌러 복사된 글자를 확인하세요.',
en: 'The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.',
});
}
function setMode(api: GridApi<Row>, next: typeof mode): void {
mode = next;
api.setColumns([
{ id: 'dept', title: '부서', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: '팀', width: 90, editable: true },
{ id: 'name', title: '이름', width: 90, editable: true },
]);
say({ ko: `mergeCopy를 '${next}'로 바꿨어요.`, en: `mergeCopy is now '${next}'.` });
}
export const actions = {
all: (api: GridApi<Row>) => setMode(api, 'all'),
first: (api: GridApi<Row>) => setMode(api, 'first'),
repeat: (api: GridApi<Row>) => setMode(api, 'repeat'),
copy: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse()) say(line.replace(/\t/g, ' | '));
say({
ko: `mergeCopy '${mode}'로 복사한 글자예요(위에서 아래 순서).`,
en: `Text copied with mergeCopy '${mode}' (top to bottom).`,
});
},
};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="first">first</button>
<button type="button" id="all">all</button>
<button type="button" id="repeat">repeat</button>
<button type="button" id="copy">Copy all</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('first').addEventListener('click', () => actions.first(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('repeat').addEventListener('click', () => actions.repeat(api));
document.getElementById('copy').addEventListener('click', () => actions.copy(api));const rows = [
{ id: 1, dept: 'Dev', team: 'Web', name: 'Chloe Adams' },
{ id: 2, dept: 'Dev', team: 'Web', name: 'Emma Stone' },
{ id: 3, dept: 'Dev', team: 'App', name: 'Daniel Parker' },
{ id: 4, dept: 'Ops', team: 'Infra', name: 'Olivia Reed' },
{ id: 5, dept: 'Design', team: 'Brand', name: 'Liam Turner' },
{ id: 6, dept: 'Design', team: 'Brand', name: 'Ava Brooks' },
];
// mergeCopy: the text used when copying a vertically merged span. 'all' (default) each cell's own text, 'first' only the first row, 'repeat' the first row's text on every row.
let mode = 'first';
export const options = {
columns: [
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say = () => { };
export function setup(_api, log) {
say = log;
log('The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.');
}
function setMode(api, next) {
mode = next;
api.setColumns([
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
]);
say(`mergeCopy is now '${next}'.`);
}
export const actions = {
all: (api) => setMode(api, 'all'),
first: (api) => setMode(api, 'first'),
repeat: (api) => setMode(api, 'repeat'),
copy: (api) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse())
say(line.replace(/\t/g, ' | '));
say(`Text copied with mergeCopy '${mode}' (top to bottom).`);
},
};<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Choose the copy text of merged cells</title>
</head>
<body>
<div class="toolbar">
<button type="button" id="first">first</button>
<button type="button" id="all">all</button>
<button type="button" id="repeat">repeat</button>
<button type="button" id="copy">Copy all</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 rows = [
{ id: 1, dept: 'Dev', team: 'Web', name: 'Chloe Adams' },
{ id: 2, dept: 'Dev', team: 'Web', name: 'Emma Stone' },
{ id: 3, dept: 'Dev', team: 'App', name: 'Daniel Parker' },
{ id: 4, dept: 'Ops', team: 'Infra', name: 'Olivia Reed' },
{ id: 5, dept: 'Design', team: 'Brand', name: 'Liam Turner' },
{ id: 6, dept: 'Design', team: 'Brand', name: 'Ava Brooks' },
];
// mergeCopy: the text used when copying a vertically merged span. 'all' (default) each cell's own text, 'first' only the first row, 'repeat' the first row's text on every row.
let mode = 'first';
const options = {
columns: [
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say = () => { };
function setup(_api, log) {
say = log;
log('The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.');
}
function setMode(api, next) {
mode = next;
api.setColumns([
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
]);
say(`mergeCopy is now '${next}'.`);
}
const actions = {
all: (api) => setMode(api, 'all'),
first: (api) => setMode(api, 'first'),
repeat: (api) => setMode(api, 'repeat'),
copy: (api) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse())
say(line.replace(/\t/g, ' | '));
say(`Text copied with mergeCopy '${mode}' (top to bottom).`);
},
};
options.ariaLabel = "Choose the copy text of merged cells";
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('first').addEventListener('click', () => actions.first(api));
document.getElementById('all').addEventListener('click', () => actions.all(api));
document.getElementById('repeat').addEventListener('click', () => actions.repeat(api));
document.getElementById('copy').addEventListener('click', () => actions.copy(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.first(api)}
>first</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.all(api)}
>all</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.repeat(api)}
>repeat</button>
<button
type="button"
disabled={!api}
onClick={() => api && actions.copy(api)}
>Copy all</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;
dept: string;
team: string;
name: string;
}
const rows: Row[] = [
{ id: 1, dept: 'Dev', team: 'Web', name: 'Chloe Adams' },
{ id: 2, dept: 'Dev', team: 'Web', name: 'Emma Stone' },
{ id: 3, dept: 'Dev', team: 'App', name: 'Daniel Parker' },
{ id: 4, dept: 'Ops', team: 'Infra', name: 'Olivia Reed' },
{ id: 5, dept: 'Design', team: 'Brand', name: 'Liam Turner' },
{ id: 6, dept: 'Design', team: 'Brand', name: 'Ava Brooks' },
];
// mergeCopy: the text used when copying a vertically merged span. 'all' (default) each cell's own text, 'first' only the first row, 'repeat' the first row's text on every row.
let mode: 'all' | 'first' | 'repeat' = 'first';
export const options: GridOptions<Row> = {
columns: [
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(
'The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.',
);
}
function setMode(api: GridApi<Row>, next: typeof mode): void {
mode = next;
api.setColumns([
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
]);
say(`mergeCopy is now '${next}'.`);
}
export const actions = {
all: (api: GridApi<Row>) => setMode(api, 'all'),
first: (api: GridApi<Row>) => setMode(api, 'first'),
repeat: (api: GridApi<Row>) => setMode(api, 'repeat'),
copy: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse()) say(line.replace(/\t/g, ' | '));
say(`Text copied with mergeCopy '${mode}' (top to bottom).`);
},
};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.first(api)">first</button>
<button type="button" :disabled="!api" @click="api && actions.all(api)">all</button>
<button type="button" :disabled="!api" @click="api && actions.repeat(api)">repeat</button>
<button type="button" :disabled="!api" @click="api && actions.copy(api)">Copy all</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;
dept: string;
team: string;
name: string;
}
const rows: Row[] = [
{ id: 1, dept: 'Dev', team: 'Web', name: 'Chloe Adams' },
{ id: 2, dept: 'Dev', team: 'Web', name: 'Emma Stone' },
{ id: 3, dept: 'Dev', team: 'App', name: 'Daniel Parker' },
{ id: 4, dept: 'Ops', team: 'Infra', name: 'Olivia Reed' },
{ id: 5, dept: 'Design', team: 'Brand', name: 'Liam Turner' },
{ id: 6, dept: 'Design', team: 'Brand', name: 'Ava Brooks' },
];
// mergeCopy: the text used when copying a vertically merged span. 'all' (default) each cell's own text, 'first' only the first row, 'repeat' the first row's text on every row.
let mode: 'all' | 'first' | 'repeat' = 'first';
export const options: GridOptions<Row> = {
columns: [
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(
'The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.',
);
}
function setMode(api: GridApi<Row>, next: typeof mode): void {
mode = next;
api.setColumns([
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
]);
say(`mergeCopy is now '${next}'.`);
}
export const actions = {
all: (api: GridApi<Row>) => setMode(api, 'all'),
first: (api: GridApi<Row>) => setMode(api, 'first'),
repeat: (api: GridApi<Row>) => setMode(api, 'repeat'),
copy: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse()) say(line.replace(/\t/g, ' | '));
say(`Text copied with mergeCopy '${mode}' (top to bottom).`);
},
};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.first(api)"
>first</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.all(api)"
>all</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.repeat(api)"
>repeat</button>
<button
type="button"
[disabled]="!api"
(click)="api && actions.copy(api)"
>Copy all</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;
dept: string;
team: string;
name: string;
}
const rows: Row[] = [
{ id: 1, dept: 'Dev', team: 'Web', name: 'Chloe Adams' },
{ id: 2, dept: 'Dev', team: 'Web', name: 'Emma Stone' },
{ id: 3, dept: 'Dev', team: 'App', name: 'Daniel Parker' },
{ id: 4, dept: 'Ops', team: 'Infra', name: 'Olivia Reed' },
{ id: 5, dept: 'Design', team: 'Brand', name: 'Liam Turner' },
{ id: 6, dept: 'Design', team: 'Brand', name: 'Ava Brooks' },
];
// mergeCopy: the text used when copying a vertically merged span. 'all' (default) each cell's own text, 'first' only the first row, 'repeat' the first row's text on every row.
let mode: 'all' | 'first' | 'repeat' = 'first';
export const options: GridOptions<Row> = {
columns: [
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: 'first', editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
],
rows,
rowKey: 'id',
cellSelection: 'multiple',
};
let say: (message: LogText) => void = () => {};
export function setup(_api: GridApi<Row>, log: (message: LogText) => void) {
say = log;
log(
'The Dept column is merged. Pick a copy mode with a button and press Copy all to see the copied text.',
);
}
function setMode(api: GridApi<Row>, next: typeof mode): void {
mode = next;
api.setColumns([
{ id: 'dept', title: 'Dept', width: 90, merge: true, mergeCopy: next, editable: true },
{ id: 'team', title: 'Team', width: 90, editable: true },
{ id: 'name', title: 'Name', width: 110, editable: true },
]);
say(`mergeCopy is now '${next}'.`);
}
export const actions = {
all: (api: GridApi<Row>) => setMode(api, 'all'),
first: (api: GridApi<Row>) => setMode(api, 'first'),
repeat: (api: GridApi<Row>) => setMode(api, 'repeat'),
copy: (api: GridApi<Row>) => {
api.selectCells({ rowKey: 1, columnId: 'dept' }, { rowKey: 6, columnId: 'name' });
const text = api.copyCells();
for (const line of text.split('\r\n').reverse()) say(line.replace(/\t/g, ' | '));
say(`Text copied with mergeCopy '${mode}' (top to bottom).`);
},
};