쪽 머리말·꼬리말을 넣어 인쇄하기Print with page headers and footers
용지 방향과 쪽당 행 수를 정하고 제목·머리말·꼬리말(쪽 번호)을 넣어 인쇄해요.Choose the paper orientation and rows per page, then print with a title, header and footer (page numbers).
코드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)
이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i maxgrid @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<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>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));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.',
});
} 이 HTML은 추가 번들(위 script 태그)도 함께 불러오고 전역 변수로 써요. 별도 설치는 필요 없어요.
<!doctype html>
<html lang="ko">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>쪽 머리말·꼬리말을 넣어 인쇄하기</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.export.min.js"></script>
<script>
const { withExport } = MaxGridExport;
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),
}));
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 = () => { };
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}`,
});
}
},
};
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.',
});
}
options.ariaLabel = "쪽 머리말·꼬리말을 넣어 인쇄하기";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
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));
</script>
</body>
</html> 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/react @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="용지 방향"
disabled={!api}
onChange={(event) => api && actions.orientation(api, event.target.value)}
>
<option value="portrait">세로</option>
<option value="landscape">가로</option>
</select>
<select defaultValue="portrait"
aria-label="쪽당 행 수"
disabled={!api}
onChange={(event) => api && actions.rowsPerPage(api, event.target.value)}
>
<option value="10">10행</option>
<option value="20">20행</option>
<option value="40">40행</option>
</select>
<input
type="text"
aria-label="제목"
placeholder="제목 (비우면 기본)"
disabled={!api}
onChange={(event) => api && actions.title(api, event.target.value)}
/>
<button
type="button"
disabled={!api}
onClick={() => api && actions.print(api)}
>인쇄</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
orderNo: string;
customer: string;
qty: number;
}
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통'];
const rows: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${4001 + i}`,
customer: customers[i % customers.length] as string,
qty: 3 + ((i * 7) % 28),
}));
export const options: GridOptions<Row> = {
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' | 'landscape' = 'portrait';
let rowsPerPage = 20;
let title = '주문 목록';
let say: (message: LogText) => void = () => {};
export const actions = {
orientation: (_api: GridApi<Row>, v?: string) =>
void (orientation = v === 'landscape' ? 'landscape' : 'portrait'),
rowsPerPage: (_api: GridApi<Row>, v?: string) => void (rowsPerPage = Number(v) || 20),
title: (_api: GridApi<Row>, v?: string) => {
title = (v ?? '').trim() || '주문 목록';
say({
ko: `인쇄 제목을 "${title}"(으)로 바꿨어요`,
en: `Print title set to "${title}"`,
});
},
print: async (api: GridApi<Row>) => {
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 as Error).message}`,
en: `Could not print: ${(e as Error).message}`,
});
}
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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.',
});
} 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/vue @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="용지 방향"
:disabled="!api"
@change="api && actions.orientation(api, ($event.target as HTMLSelectElement).value)"
>
<option value="portrait" selected>세로</option>
<option value="landscape">가로</option>
</select>
<select
aria-label="쪽당 행 수"
:disabled="!api"
@change="api && actions.rowsPerPage(api, ($event.target as HTMLSelectElement).value)"
>
<option value="10">10행</option>
<option value="20" selected>20행</option>
<option value="40">40행</option>
</select>
<input
type="text"
aria-label="제목"
placeholder="제목 (비우면 기본)"
:disabled="!api"
@input="api && actions.title(api, ($event.target as HTMLInputElement).value)"
/>
<button type="button" :disabled="!api" @click="api && actions.print(api)">인쇄</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
orderNo: string;
customer: string;
qty: number;
}
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통'];
const rows: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${4001 + i}`,
customer: customers[i % customers.length] as string,
qty: 3 + ((i * 7) % 28),
}));
export const options: GridOptions<Row> = {
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' | 'landscape' = 'portrait';
let rowsPerPage = 20;
let title = '주문 목록';
let say: (message: LogText) => void = () => {};
export const actions = {
orientation: (_api: GridApi<Row>, v?: string) =>
void (orientation = v === 'landscape' ? 'landscape' : 'portrait'),
rowsPerPage: (_api: GridApi<Row>, v?: string) => void (rowsPerPage = Number(v) || 20),
title: (_api: GridApi<Row>, v?: string) => {
title = (v ?? '').trim() || '주문 목록';
say({
ko: `인쇄 제목을 "${title}"(으)로 바꿨어요`,
en: `Print title set to "${title}"`,
});
},
print: async (api: GridApi<Row>) => {
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 as Error).message}`,
en: `Could not print: ${(e as Error).message}`,
});
}
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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.',
});
} 이 예제는 추가 패키지가 필요해요. 내 컴퓨터에서 돌리려면 npm i @maxgrid/angular @maxgrid/export로 설치하세요.
버튼을 누르면 이 예제의 코드가 StackBlitz나 CodeSandbox로 전송돼요. 누르기 전에는 아무것도 보내지 않아요.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="용지 방향"
[disabled]="!api"
(change)="api && actions.orientation(api, $any($event.target).value)"
>
<option value="portrait" selected>세로</option>
<option value="landscape">가로</option>
</select>
<select
aria-label="쪽당 행 수"
[disabled]="!api"
(change)="api && actions.rowsPerPage(api, $any($event.target).value)"
>
<option value="10">10행</option>
<option value="20" selected>20행</option>
<option value="40">40행</option>
</select>
<input
type="text"
aria-label="제목"
placeholder="제목 (비우면 기본)"
[disabled]="!api"
(input)="api && actions.title(api, $any($event.target).value)"
/>
<button
type="button"
[disabled]="!api"
(click)="api && actions.print(api)"
>인쇄</button>
</div>
<mx-grid style="height: 300px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string | { ko: string; en: string };
export interface Row {
id: number;
orderNo: string;
customer: string;
qty: number;
}
const customers = ['한빛푸드', '소나무철물', '파란마켓', '단풍상회', '바다유통'];
const rows: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${4001 + i}`,
customer: customers[i % customers.length] as string,
qty: 3 + ((i * 7) % 28),
}));
export const options: GridOptions<Row> = {
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' | 'landscape' = 'portrait';
let rowsPerPage = 20;
let title = '주문 목록';
let say: (message: LogText) => void = () => {};
export const actions = {
orientation: (_api: GridApi<Row>, v?: string) =>
void (orientation = v === 'landscape' ? 'landscape' : 'portrait'),
rowsPerPage: (_api: GridApi<Row>, v?: string) => void (rowsPerPage = Number(v) || 20),
title: (_api: GridApi<Row>, v?: string) => {
title = (v ?? '').trim() || '주문 목록';
say({
ko: `인쇄 제목을 "${title}"(으)로 바꿨어요`,
en: `Print title set to "${title}"`,
});
},
print: async (api: GridApi<Row>) => {
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 as Error).message}`,
en: `Could not print: ${(e as Error).message}`,
});
}
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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.',
});
} 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.
<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>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));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.');
}This HTML also loads an extra bundle (the extra script tag above) and uses it as a global. No install is needed.
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8" />
<meta name="viewport" content="width=device-width, initial-scale=1" />
<title>Print with page headers and footers</title>
</head>
<body>
<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>
<ul id="log" aria-live="polite"></ul>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.min.js"></script>
<script src="https://cdn.maxmine.com/maxgrid/latest/maxgrid.export.min.js"></script>
<script>
const { withExport } = MaxGridExport;
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),
}));
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 = () => { };
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}`);
}
},
};
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.');
}
options.ariaLabel = "Print with page headers and footers";
const api = MaxGrid.createGrid(document.getElementById('grid'), options);
setup(api, (message) => {
const item = document.createElement('li');
item.textContent =
typeof message === 'string' ? message : navigator.language.startsWith('ko') ? message.ko : message.en;
document.getElementById('log').prepend(item);
});
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));
</script>
</body>
</html> This example needs an extra package. To run it locally, install with npm i @maxgrid/react @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { useEffect } from 'react';
import { Grid, useGridApi } from '@maxgrid/react';
import { actions, options, setup, type Row } from './example';
export function ExampleGrid() {
const [api, gridRef] = useGridApi<Row>();
useEffect(() => (api ? setup(api, console.log) : undefined), [api]);
return (
<>
<div className="toolbar">
<select
aria-label="Orientation"
disabled={!api}
onChange={(event) => api && actions.orientation(api, event.target.value)}
>
<option value="portrait">Portrait</option>
<option value="landscape">Landscape</option>
</select>
<select defaultValue="portrait"
aria-label="Rows per page"
disabled={!api}
onChange={(event) => api && actions.rowsPerPage(api, event.target.value)}
>
<option value="10">10 rows</option>
<option value="20">20 rows</option>
<option value="40">40 rows</option>
</select>
<input
type="text"
aria-label="Title"
placeholder="Title (blank = default)"
disabled={!api}
onChange={(event) => api && actions.title(api, event.target.value)}
/>
<button
type="button"
disabled={!api}
onClick={() => api && actions.print(api)}
>Print</button>
</div>
<Grid style={{ height: 300 }} ref={gridRef} options={options} />
</>
);
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/react';
export type LogText = string;
export interface Row {
id: number;
orderNo: string;
customer: string;
qty: number;
}
const customers = ['Harbor Foods', 'Pine Hardware', 'Blue Market', 'Maple Store', 'Ocean Trade'];
const rows: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${4001 + i}`,
customer: customers[i % customers.length] as string,
qty: 3 + ((i * 7) % 28),
}));
export const options: GridOptions<Row> = {
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' | 'landscape' = 'portrait';
let rowsPerPage = 20;
let title = 'Order list';
let say: (message: LogText) => void = () => {};
export const actions = {
orientation: (_api: GridApi<Row>, v?: string) =>
void (orientation = v === 'landscape' ? 'landscape' : 'portrait'),
rowsPerPage: (_api: GridApi<Row>, v?: string) => void (rowsPerPage = Number(v) || 20),
title: (_api: GridApi<Row>, v?: string) => {
title = (v ?? '').trim() || 'Order list';
say(`Print title set to "${title}"`);
},
print: async (api: GridApi<Row>) => {
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 as Error).message}`);
}
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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.',
);
} This example needs an extra package. To run it locally, install with npm i @maxgrid/vue @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
<script setup lang="ts">
import { onBeforeUnmount, shallowRef } from 'vue';
import { Grid, type GridApi } from '@maxgrid/vue';
import { actions, options, setup, type Row } from './example';
const api = shallowRef<GridApi<Row> | null>(null);
let stop: (() => void) | undefined;
function onReady(event: { api: GridApi<Row> }) {
api.value = event.api;
stop = setup(event.api, console.log);
}
onBeforeUnmount(() => stop?.());
</script>
<template>
<div class="toolbar">
<select
aria-label="Orientation"
:disabled="!api"
@change="api && actions.orientation(api, ($event.target as HTMLSelectElement).value)"
>
<option value="portrait" selected>Portrait</option>
<option value="landscape">Landscape</option>
</select>
<select
aria-label="Rows per page"
:disabled="!api"
@change="api && actions.rowsPerPage(api, ($event.target as HTMLSelectElement).value)"
>
<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)"
:disabled="!api"
@input="api && actions.title(api, ($event.target as HTMLInputElement).value)"
/>
<button type="button" :disabled="!api" @click="api && actions.print(api)">Print</button>
</div>
<Grid style="height: 300px" :options="options" @ready="onReady" />
</template>import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/vue';
export type LogText = string;
export interface Row {
id: number;
orderNo: string;
customer: string;
qty: number;
}
const customers = ['Harbor Foods', 'Pine Hardware', 'Blue Market', 'Maple Store', 'Ocean Trade'];
const rows: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${4001 + i}`,
customer: customers[i % customers.length] as string,
qty: 3 + ((i * 7) % 28),
}));
export const options: GridOptions<Row> = {
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' | 'landscape' = 'portrait';
let rowsPerPage = 20;
let title = 'Order list';
let say: (message: LogText) => void = () => {};
export const actions = {
orientation: (_api: GridApi<Row>, v?: string) =>
void (orientation = v === 'landscape' ? 'landscape' : 'portrait'),
rowsPerPage: (_api: GridApi<Row>, v?: string) => void (rowsPerPage = Number(v) || 20),
title: (_api: GridApi<Row>, v?: string) => {
title = (v ?? '').trim() || 'Order list';
say(`Print title set to "${title}"`);
},
print: async (api: GridApi<Row>) => {
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 as Error).message}`);
}
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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.',
);
} This example needs an extra package. To run it locally, install with npm i @maxgrid/angular @maxgrid/export.
When you click, the example code is sent to StackBlitz or CodeSandbox. Nothing is sent before you click.
import { Component, OnDestroy } from '@angular/core';
import { GridComponent, isGridEvent, type GridApi, type GridEventMessage } from '@maxgrid/angular';
import { actions, options, setup, type Row } from './example';
@Component({
selector: 'app-example-grid',
standalone: true,
imports: [GridComponent],
template: `
<div class="toolbar">
<select
aria-label="Orientation"
[disabled]="!api"
(change)="api && actions.orientation(api, $any($event.target).value)"
>
<option value="portrait" selected>Portrait</option>
<option value="landscape">Landscape</option>
</select>
<select
aria-label="Rows per page"
[disabled]="!api"
(change)="api && actions.rowsPerPage(api, $any($event.target).value)"
>
<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)"
[disabled]="!api"
(input)="api && actions.title(api, $any($event.target).value)"
/>
<button
type="button"
[disabled]="!api"
(click)="api && actions.print(api)"
>Print</button>
</div>
<mx-grid style="height: 300px" [options]="options" [events]="relayed" (gridEvent)="onEvent($event)" />
`,
})
export class ExampleGridComponent implements OnDestroy {
readonly options = options;
readonly actions = actions;
readonly relayed = ['ready'] as const;
api: GridApi<Row> | null = null;
private stop: (() => void) | null = null;
onEvent(event: GridEventMessage<Row>): void {
if (isGridEvent(event, 'ready')) {
this.api = event.payload.api;
this.stop = setup(this.api, console.log);
}
}
ngOnDestroy(): void {
this.stop?.();
}
}import { withExport } from '@maxgrid/export';
import type { GridApi, GridOptions } from '@maxgrid/angular';
export type LogText = string;
export interface Row {
id: number;
orderNo: string;
customer: string;
qty: number;
}
const customers = ['Harbor Foods', 'Pine Hardware', 'Blue Market', 'Maple Store', 'Ocean Trade'];
const rows: Row[] = Array.from({ length: 40 }, (_, i) => ({
id: i + 1,
orderNo: `SO-${4001 + i}`,
customer: customers[i % customers.length] as string,
qty: 3 + ((i * 7) % 28),
}));
export const options: GridOptions<Row> = {
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' | 'landscape' = 'portrait';
let rowsPerPage = 20;
let title = 'Order list';
let say: (message: LogText) => void = () => {};
export const actions = {
orientation: (_api: GridApi<Row>, v?: string) =>
void (orientation = v === 'landscape' ? 'landscape' : 'portrait'),
rowsPerPage: (_api: GridApi<Row>, v?: string) => void (rowsPerPage = Number(v) || 20),
title: (_api: GridApi<Row>, v?: string) => {
title = (v ?? '').trim() || 'Order list';
say(`Print title set to "${title}"`);
},
print: async (api: GridApi<Row>) => {
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 as Error).message}`);
}
},
};
export function setup(api: GridApi<Row>, log: (message: LogText) => void) {
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.',
);
}