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

합계 줄을 위쪽에 두기Put the total row at the top

합계 줄을 맨 아래 대신 헤더 바로 아래에 둘 수 있어요. 숫자가 많은 표에서 합계를 먼저 보여 주고 싶을 때 좋아요.Place the total row right under the header instead of at the bottom, handy when the total matters most in a long table.

입문Beginner
직접 써 보기Live preview합계 줄을 위쪽에 두기Put the total row at the top

코드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="position">
      <option value="top" selected>위</option>
      <option value="bottom">아래</option>
      <option value="off">숨기기</option>
    </select>
  </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 } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));
example.js
const branches = [
  '서울 본점',
  '강남점',
  '부산점',
  '대구점',
  '인천점',
  '광주점',
  '대전점',
  '제주점',
];
const regions = ['수도권', '수도권', '영남', '영남', '수도권', '호남', '충청', '제주'];
// 단위는 백만원이에요. 지점마다 1~6월 매출이 있어요.
const sales = (i, k) => 20 + ((i * 13 + k * 7) % 70);
const rows = branches.map((branch, i) => ({
  id: i + 1,
  branch,
  region: regions[i],
  m1: sales(i, 1),
  m2: sales(i, 2),
  m3: sales(i, 3),
  m4: sales(i, 4),
  m5: sales(i, 5),
  m6: sales(i, 6),
}));
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const money = (value) => Number(value).toLocaleString('ko-KR');
export const options = {
  columns: [
    { id: 'branch', title: '지점', width: 120 },
    ...months.map((id, k) => ({
      id,
      title: `${k + 1}월`,
      kind: 'number',
      width: 90,
      align: 'end',
      aggregate: 'sum',
      formatValue: money,
      aggregateFormat: money,
    })),
  ],
  rows,
  rowKey: 'id',
  // position: 'top'이면 합계 줄이 헤더 바로 아래로 올라와요. 기본은 'bottom'이에요.
  summary: { position: 'top', label: '합계' },
};
export const actions = {
  position: (api, value) => api.setOptions({
    summary: value === 'off'
      ? false
      : { position: value === 'bottom' ? 'bottom' : 'top', label: '합계' },
  }),
};

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="Total row position" id="position">
      <option value="top" selected>Top</option>
      <option value="bottom">Bottom</option>
      <option value="off">Hidden</option>
    </select>
  </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 } from './example';
const api = createGrid(document.getElementById('grid'), options);
document.getElementById('position').addEventListener('change', (event) => actions.position(api, event.target.value));
example.js
const branches = ['Seoul HQ', 'Gangnam', 'Busan', 'Daegu', 'Incheon', 'Gwangju', 'Daejeon', 'Jeju'];
const regions = [
  'Capital',
  'Capital',
  'Yeongnam',
  'Yeongnam',
  'Capital',
  'Honam',
  'Chungcheong',
  'Jeju',
];
// Units are $ thousands. Each branch has sales for January to June.
const sales = (i, k) => 20 + ((i * 13 + k * 7) % 70);
const rows = branches.map((branch, i) => ({
  id: i + 1,
  branch,
  region: regions[i],
  m1: sales(i, 1),
  m2: sales(i, 2),
  m3: sales(i, 3),
  m4: sales(i, 4),
  m5: sales(i, 5),
  m6: sales(i, 6),
}));
const months = ['m1', 'm2', 'm3', 'm4', 'm5', 'm6'];
const money = (value) => Number(value).toLocaleString('en-US');
export const options = {
  columns: [
    { id: 'branch', title: 'Branch', width: 120 },
    ...months.map((id, k) => ({
      id,
      title: ['Jan', 'Feb', 'Mar', 'Apr', 'May', 'Jun'][k],
      kind: 'number',
      width: 90,
      align: 'end',
      aggregate: 'sum',
      formatValue: money,
      aggregateFormat: money,
    })),
  ],
  rows,
  rowKey: 'id',
  // With position: 'top' the summary row moves right below the header. The default is 'bottom'.
  summary: { position: 'top', label: 'Total' },
};
export const actions = {
  position: (api, value) => api.setOptions({
    summary: value === 'off'
      ? false
      : { position: value === 'bottom' ? 'bottom' : 'top', label: 'Total' },
  }),
};