본문으로 건너뛰기Skip to content
예제 첫화면Examples home

합친 칸의 복사 글자 정하기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.

활용Intermediate
직접 써 보기Live preview합친 칸의 복사 글자 정하기Choose the copy text of merged cells

코드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)

빌드 도구(Vite 등)를 쓰는 프로젝트용 모듈 파일이에요. 설치 없이 바로 돌려 보려면 HTML 탭이나 직접 해보기를 쓰세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<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>
main.js
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));
example.js
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).`,
    });
  },
};

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.

index.html
<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>
main.js
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));
example.js
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).`);
  },
};