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

그룹 보기 방식: 컬럼 숨기기·줄 숨기기·병합Group display: hide columns, hide rows, merged

grouping.hideColumns는 묶인 컬럼을 묶여 있는 동안 숨기고, hideRows는 그룹 줄 없이 행을 그룹 순서로 보이고, merged는 그룹 컬럼 칸을 값별로 세로 병합해요.grouping.hideColumns hides grouped columns while grouped, hideRows shows rows in group order without group lines, and merged merges the group column cells by value.

활용Intermediate
직접 써 보기Live preview그룹 보기 방식: 컬럼 숨기기·줄 숨기기·병합Group display: hide columns, hide rows, merged

코드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="plain">기본</button>
    <button type="button" id="hideColumns">컬럼 숨기기</button>
    <button type="button" id="hideRows">줄 숨기기</button>
    <button type="button" id="merged">병합</button>
    <button type="button" id="ungroup">묶음 풀기</button>
  </div>
  <div id="grid" style="height: 420px"></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('plain').addEventListener('click', () => actions.plain(api));
document.getElementById('hideColumns').addEventListener('click', () => actions.hideColumns(api));
document.getElementById('hideRows').addEventListener('click', () => actions.hideRows(api));
document.getElementById('merged').addEventListener('click', () => actions.merged(api));
document.getElementById('ungroup').addEventListener('click', () => actions.ungroup(api));
example.js
const TEAMS = ['개발', '디자인', '영업'];
const CITIES = ['서울', '부산'];
const rows = TEAMS.flatMap((team, t) => CITIES.flatMap((city, c) => [0, 1].map((k) => ({
  id: t * 4 + c * 2 + k + 1,
  team,
  city,
  name: `사원 ${t * 4 + c * 2 + k + 1}`,
  amount: 100 + t * 20 + c * 10 + k * 5,
}))));
export const options = {
  columns: [
    { id: 'team', title: '팀', width: 110 },
    { id: 'city', title: '도시', width: 100 },
    { id: 'name', title: '이름', width: 120 },
    { id: 'amount', title: '금액', kind: 'number', width: 100, aggregate: 'sum' },
  ],
  rows,
  rowKey: 'id',
  grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  return () => { };
}
function mode(api, grouping, ko, en) {
  api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } });
  say({ ko, en });
}
export const actions = {
  plain: (api) => mode(api, {}, '기본: 그룹 줄이 있어요', 'Default: group lines are shown'),
  hideColumns: (api) => mode(api, { hideColumns: true }, '묶인 컬럼(팀·도시)이 숨겨져요', 'Grouped columns (team, city) are hidden'),
  hideRows: (api) => mode(api, { hideRows: true }, '그룹 줄 없이 행이 그룹 순서로 이어져요', 'No group lines; rows follow group order'),
  merged: (api) => mode(api, { merged: true }, '그룹 컬럼 칸이 값별로 세로 병합돼요', 'Group column cells are merged by value'),
  ungroup: (api) => {
    api.setGroupBy([]);
    say({ ko: '묶음을 풀면 숨긴 컬럼이 돌아와요', en: 'Ungrouping brings hidden columns back' });
  },
};

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="plain">Default</button>
    <button type="button" id="hideColumns">Hide columns</button>
    <button type="button" id="hideRows">Hide rows</button>
    <button type="button" id="merged">Merged</button>
    <button type="button" id="ungroup">Ungroup</button>
  </div>
  <div id="grid" style="height: 420px"></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('plain').addEventListener('click', () => actions.plain(api));
document.getElementById('hideColumns').addEventListener('click', () => actions.hideColumns(api));
document.getElementById('hideRows').addEventListener('click', () => actions.hideRows(api));
document.getElementById('merged').addEventListener('click', () => actions.merged(api));
document.getElementById('ungroup').addEventListener('click', () => actions.ungroup(api));
example.js
const TEAMS = ['Dev', 'Design', 'Sales'];
const CITIES = ['New York', 'Boston'];
const rows = TEAMS.flatMap((team, t) => CITIES.flatMap((city, c) => [0, 1].map((k) => ({
  id: t * 4 + c * 2 + k + 1,
  team,
  city,
  name: `Employee ${t * 4 + c * 2 + k + 1}`,
  amount: 100 + t * 20 + c * 10 + k * 5,
}))));
export const options = {
  columns: [
    { id: 'team', title: 'Team', width: 110 },
    { id: 'city', title: 'City', width: 100 },
    { id: 'name', title: 'Name', width: 120 },
    { id: 'amount', title: 'Amount', kind: 'number', width: 100, aggregate: 'sum' },
  ],
  rows,
  rowKey: 'id',
  grouping: { by: ['team', 'city'], expandDepth: 'all' },
};
let say = () => { };
export function setup(_api, log) {
  say = log;
  return () => { };
}
function mode(api, grouping, message) {
  api.setOptions({ grouping: { by: ['team', 'city'], expandDepth: 'all', ...grouping } });
  say(message);
}
export const actions = {
  plain: (api) => mode(api, {}, 'Default: group lines are shown'),
  hideColumns: (api) => mode(api, { hideColumns: true }, 'Grouped columns (team, city) are hidden'),
  hideRows: (api) => mode(api, { hideRows: true }, 'No group lines; rows follow group order'),
  merged: (api) => mode(api, { merged: true }, 'Group column cells are merged by value'),
  ungroup: (api) => {
    api.setGroupBy([]);
    say('Ungrouping brings hidden columns back');
  },
};