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

합친 칸을 구간 전체로 선택하기Select a merged span as a whole

selection.mergeSelect가 'span'이면 합친 구간의 어느 칸을 골라도, 끌어서 일부만 덮어도 구간 전체가 선택돼요(세로·가로 병합 모두). 'cell'(기본)은 누른 칸만이에요. selection.mergeCheck를 켜면 체크 칸을 구간의 첫 줄에만 그리고 누르면 구간의 모든 줄을 함께 선택·해제해요.With selection.mergeSelect 'span', choosing any cell of a merged span, or dragging over part of it, selects the whole span (vertical and horizontal merges). 'cell' (default) selects only the pressed cell. selection.mergeCheck draws the check cell only on the first row of a span and selects or clears every row of it.

활용Intermediate
직접 써 보기Live preview합친 칸을 구간 전체로 선택하기Select a merged span as a whole

코드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="mode">
      <option value="span" selected>구간 전체(span)</option>
      <option value="cell">그 칸만(cell)</option>
    </select>
  </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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
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: '강서윤' },
];
// selection.mergeSelect: 'cell'(기본)은 누른 칸만, 'span'은 합친 구간 전체를 선택해요. 셀 선택 범위는 칸 선택(cellSelection)에서 보여요.
export const options = {
  columns: [
    { id: 'dept', title: '부서', width: 90, merge: true },
    { id: 'team', title: '팀', width: 90, merge: true, mergeWithin: 'dept' },
    { id: 'name', title: '이름', width: 90 },
  ],
  rows,
  rowKey: 'id',
  cellSelection: 'multiple',
  selection: { mode: 'multiple', checkbox: true, mergeSelect: 'span', mergeCheck: true },
};
export function setup(api, log) {
  log({
    ko: '"부서"나 "팀"의 합친 칸을 눌러 보세요. 구간 전체가 선택돼요. 체크 칸은 구간의 첫 줄에만 있고 누르면 구간의 모든 줄이 선택돼요.',
    en: 'Press a merged Dept or Team cell: the whole span is selected. The check cell is only on the first row of a span and selects every row of it.',
  });
  return api.on('cellSelectionChanged', (e) => log({
    ko: `선택 범위 ${e.ranges.length}개: ${e.ranges.map((r) => `${r.from.rowKey}${r.from.columnId}→${r.to.rowKey}${r.to.columnId}`).join(', ')}`,
    en: `${e.ranges.length} ranges: ${e.ranges.map((r) => `${r.from.rowKey}${r.from.columnId}→${r.to.rowKey}${r.to.columnId}`).join(', ')}`,
  }));
}
export const actions = {
  mode: (api, value) => api.setOptions({
    selection: {
      mode: 'multiple',
      checkbox: true,
      mergeSelect: value === 'cell' ? 'cell' : 'span',
      mergeCheck: value !== 'cell',
    },
  }),
};

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="Select mode" id="mode">
      <option value="span" selected>Whole span</option>
      <option value="cell">Cell only</option>
    </select>
  </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('mode').addEventListener('change', (event) => actions.mode(api, event.target.value));
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' },
];
// selection.mergeSelect: 'cell' (default) selects only the pressed cell, 'span' selects the whole merged span. Cell selection ranges are shown by cellSelection.
export const options = {
  columns: [
    { id: 'dept', title: 'Dept', width: 90, merge: true },
    { id: 'team', title: 'Team', width: 90, merge: true, mergeWithin: 'dept' },
    { id: 'name', title: 'Name', width: 110 },
  ],
  rows,
  rowKey: 'id',
  cellSelection: 'multiple',
  selection: { mode: 'multiple', checkbox: true, mergeSelect: 'span', mergeCheck: true },
};
export function setup(api, log) {
  log('Press a merged Dept or Team cell: the whole span is selected. The check cell is only on the first row of a span and selects every row of it.');
  return api.on('cellSelectionChanged', (e) => log(`${e.ranges.length} ranges: ${e.ranges.map((r) => `${r.from.rowKey}${r.from.columnId}→${r.to.rowKey}${r.to.columnId}`).join(', ')}`));
}
export const actions = {
  mode: (api, value) => api.setOptions({
    selection: {
      mode: 'multiple',
      checkbox: true,
      mergeSelect: value === 'cell' ? 'cell' : 'span',
      mergeCheck: value !== 'cell',
    },
  }),
};