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

앞 칸이 같은 구간 안에서만 합치기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.

활용Intermediate
직접 써 보기Live preview앞 칸이 같은 구간 안에서만 합치기Merge only inside the group to its left

코드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">
    <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>
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('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));
example.js
// '공통'이 팀마다 나오지만, 서로 다른 팀의 '공통'까지 한 칸으로 합치면 헷갈려요.
// 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}`,
    });
  });
}

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">
    <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>
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('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));
example.js
// '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}`);
  });
}