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

분류 아래 상품, 소계는 분류 줄에Products under categories, totals on the category row

분류를 숨기고 '상품 / 분류' 한 칸에 분류 이름과 상품을 들여쓰기로 이어 보여 줘요. 소계는 별도 줄 없이 분류 줄에 함께 나와서, 접으면 분류별 판매량과 매출만 깔끔하게 남아요.The category column is hidden and category names with their products indent inside one Product / Category column. Subtotals live on the category rows, so folding leaves a clean list of totals.

입문Beginner
직접 써 보기Live preview분류 아래 상품, 소계는 분류 줄에Products under categories, totals on the category row

코드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="fold">
      <option value="all" selected>모두 펼치기</option>
      <option value="none">모두 접기</option>
    </select>
  </div>
  <div id="grid" style="height: 440px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('fold').addEventListener('change', (event) => actions.fold(api, event.target.value));
example.js
// 분류 → 상품 순서로 묶은 매출표예요. 분류 이름 줄에 소계가 함께 보여요.
const DATA = [
  ['음료', ['아메리카노', '카페라떼', '녹차라떼']],
  ['베이커리', ['크루아상', '치즈케이크']],
  ['디저트', ['마카롱', '푸딩', '쿠키']],
];
const rows = [];
for (const [category, products] of DATA) {
  for (const product of products) {
    const id = rows.length + 1;
    rows.push({
      id,
      category,
      product,
      quantity: 12 + ((id * 17) % 80),
      amount: 4500 * (12 + ((id * 17) % 80)),
    });
  }
}
// 분류 컬럼은 숨기고, '상품 / 분류' 한 칸에 분류 이름과 상품이 들여쓰기로 이어져요.
// 소계는 따로 줄을 만들지 않고 분류 이름 줄에 함께 적어요.
export const options = {
  columns: [
    { id: 'category', title: '분류', width: 100, hidden: true },
    { id: 'product', title: '상품 / 분류', width: 220, aggregate: 'rowCount' },
    { id: 'quantity', title: '판매량', kind: 'number', width: 100, align: 'end', aggregate: 'sum' },
    {
      id: 'amount',
      title: '매출(원)',
      kind: 'number',
      width: 140,
      align: 'end',
      aggregate: 'sum',
      formatValue: (value) => Number(value).toLocaleString('ko-KR'),
    },
  ],
  rows,
  rowKey: 'id',
  grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
  summary: { label: '전체 합계' },
};
export const actions = {
  fold: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};

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="Expansion" id="fold">
      <option value="all" selected>Expand all</option>
      <option value="none">Collapse all</option>
    </select>
  </div>
  <div id="grid" style="height: 440px"></div>
</div>
<script type="module" src="./main.js"></script>
main.js
import { createGrid } from 'maxgrid';
import { actions, options } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('fold').addEventListener('change', (event) => actions.fold(api, event.target.value));
example.js
// A sales table grouped by category, then product. The subtotal shows on the category name row.
const DATA = [
  ['Drinks', ['Americano', 'Latte', 'Green tea latte']],
  ['Bakery', ['Croissant', 'Cheesecake']],
  ['Dessert', ['Macaron', 'Pudding', 'Cookie']],
];
const rows = [];
for (const [category, products] of DATA) {
  for (const product of products) {
    const id = rows.length + 1;
    rows.push({
      id,
      category,
      product,
      quantity: 12 + ((id * 17) % 80),
      amount: 5 * (12 + ((id * 17) % 80)),
    });
  }
}
// The category column is hidden; in the single "Product / Category" column the category name and the indented products run together.
// The subtotal gets no row of its own and is written on the category name row.
export const options = {
  columns: [
    { id: 'category', title: 'Category', width: 100, hidden: true },
    { id: 'product', title: 'Product / Category', width: 220, aggregate: 'rowCount' },
    {
      id: 'quantity',
      title: 'Units sold',
      kind: 'number',
      width: 130,
      align: 'end',
      aggregate: 'sum',
    },
    {
      id: 'amount',
      title: 'Revenue ($)',
      kind: 'number',
      width: 140,
      align: 'end',
      aggregate: 'sum',
      formatValue: (value) => Number(value).toLocaleString('en-US'),
    },
  ],
  rows,
  rowKey: 'id',
  grouping: { by: ['category'], column: 'product', expandDepth: 'all', summary: 'header' },
  summary: { label: 'Grand total' },
};
export const actions = {
  fold: (api, value) => value === 'none' ? api.collapseAll() : api.expandAll(),
};