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

쪽 머리말·꼬리말을 넣어 인쇄하기Print with page headers and footers

용지 방향과 쪽당 행 수를 정하고 제목·머리말·꼬리말(쪽 번호)을 넣어 인쇄해요.Choose the paper orientation and rows per page, then print with a title, header and footer (page numbers).

활용Intermediate
직접 써 보기Live preview쪽 머리말·꼬리말을 넣어 인쇄하기Print with page headers and footers

코드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 탭이나 직접 해보기를 쓰세요.

이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/export로 설치하세요.

버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.

index.html
<div id="app">
  <div class="toolbar">
    <select aria-label="용지 방향" id="orientation">
      <option value="portrait" selected>세로</option>
      <option value="landscape">가로</option>
    </select>
    <select aria-label="쪽당 행 수" id="rowsPerPage">
      <option value="10">10행</option>
      <option value="20" selected>20행</option>
      <option value="40">40행</option>
    </select>
    <input type="text" aria-label="제목" placeholder="제목 (비우면 기본)" id="title" />
    <button type="button" id="print">인쇄</button>
  </div>
  <div id="grid" style="height: 300px"></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('orientation').addEventListener('change', (event) => actions.orientation(api, event.target.value));
document.getElementById('rowsPerPage').addEventListener('change', (event) => actions.rowsPerPage(api, event.target.value));
document.getElementById('title').addEventListener('input', (event) => actions.title(api, event.target.value));
document.getElementById('print').addEventListener('click', () => actions.print(api));
example.js
import { withExport } from '@maxgrid/export';
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통'];
const rows = Array.from({ length: 40 }, (_, i) => ({
  id: i + 1,
  orderNo: `SO-${4001 + i}`,
  customer: customers[i % customers.length],
  qty: 3 + ((i * 7) % 28),
}));
export const options = {
  columns: [
    { id: 'orderNo', title: '주문번호', width: 110 },
    { id: 'customer', title: '거래처', width: 130 },
    { id: 'qty', title: '수량', kind: 'number', width: 80, align: 'end' },
  ],
  rows,
  rowKey: 'id',
};
let orientation = 'portrait';
let rowsPerPage = 20;
let title = '주문 목록';
let say = () => { };
export const actions = {
  orientation: (_api, v) => void (orientation = v === 'landscape' ? 'landscape' : 'portrait'),
  rowsPerPage: (_api, v) => void (rowsPerPage = Number(v) || 20),
  title: (_api, v) => {
    title = (v ?? '').trim() || '주문 목록';
    say({
      ko: `인쇄 제목을 "${title}"(으)로 바꿨어요`,
      en: `Print title set to "${title}"`,
    });
  },
  print: async (api) => {
    try {
      await withExport(api).print({
        scope: 'all',
        orientation,
        rowsPerPage,
        title,
        header: '맥스그리드 · 주문',
        footer: '{page} / {pages}쪽',
      });
      say({
        ko: `인쇄 창을 열었어요 (${orientation === 'landscape' ? '가로' : '세로'} · 쪽당 ${rowsPerPage}행 · 머리글 반복)`,
        en: `Print dialog opened (${orientation} · ${rowsPerPage} rows per page · header repeated)`,
      });
    }
    catch (e) {
      say({
        ko: `인쇄하지 못했어요: ${e.message}`,
        en: `Could not print: ${e.message}`,
      });
    }
  },
};
export function setup(api, log) {
  say = log;
  withExport(api);
  log({
    ko: '40행을 쪽마다 제목·머리말·꼬리말(쪽 번호)을 붙여 인쇄해요. 브라우저 설정에 따라 인쇄 창이 막힐 수 있어요.',
    en: 'Prints 40 rows with a title, header and footer (page numbers) on every page. Browser settings may block the print dialog.',
  });
}

Module files for a project with a bundler such as Vite. To run it with no setup, use the HTML tab or Try it.

This example needs an extra package. To run it locally, install with npm i maxgrid @maxgrid/export.

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="Orientation" id="orientation">
      <option value="portrait" selected>Portrait</option>
      <option value="landscape">Landscape</option>
    </select>
    <select aria-label="Rows per page" id="rowsPerPage">
      <option value="10">10 rows</option>
      <option value="20" selected>20 rows</option>
      <option value="40">40 rows</option>
    </select>
    <input
      type="text"
      aria-label="Title"
      placeholder="Title (blank = default)"
      id="title"
    />
    <button type="button" id="print">Print</button>
  </div>
  <div id="grid" style="height: 300px"></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('orientation').addEventListener('change', (event) => actions.orientation(api, event.target.value));
document.getElementById('rowsPerPage').addEventListener('change', (event) => actions.rowsPerPage(api, event.target.value));
document.getElementById('title').addEventListener('input', (event) => actions.title(api, event.target.value));
document.getElementById('print').addEventListener('click', () => actions.print(api));
example.js
import { withExport } from '@maxgrid/export';
const customers = ['Harbor Foods', 'Pine Hardware', 'Blue Market', 'Maple Store', 'Ocean Trade'];
const rows = Array.from({ length: 40 }, (_, i) => ({
  id: i + 1,
  orderNo: `SO-${4001 + i}`,
  customer: customers[i % customers.length],
  qty: 3 + ((i * 7) % 28),
}));
export const options = {
  columns: [
    { id: 'orderNo', title: 'Order no.', width: 110 },
    { id: 'customer', title: 'Customer', width: 130 },
    { id: 'qty', title: 'Qty', kind: 'number', width: 80, align: 'end' },
  ],
  rows,
  rowKey: 'id',
};
let orientation = 'portrait';
let rowsPerPage = 20;
let title = 'Order list';
let say = () => { };
export const actions = {
  orientation: (_api, v) => void (orientation = v === 'landscape' ? 'landscape' : 'portrait'),
  rowsPerPage: (_api, v) => void (rowsPerPage = Number(v) || 20),
  title: (_api, v) => {
    title = (v ?? '').trim() || 'Order list';
    say(`Print title set to "${title}"`);
  },
  print: async (api) => {
    try {
      await withExport(api).print({
        scope: 'all',
        orientation,
        rowsPerPage,
        title,
        header: 'MaxGrid · Orders',
        footer: 'Page {page} of {pages}',
      });
      say(`Print dialog opened (${orientation} · ${rowsPerPage} rows per page · header repeated)`);
    }
    catch (e) {
      say(`Could not print: ${e.message}`);
    }
  },
};
export function setup(api, log) {
  say = log;
  withExport(api);
  log('Prints 40 rows with a title, header and footer (page numbers) on every page. Browser settings may block the print dialog.');
}