Printing
print() prints the rows on the paper you choose with a title, page numbers and header rows repeated on every page; getPrintHtml gives a preview.
Live demoPrinting
Print on the paper you choose, with header rows repeated on every page, a title and page numbers.
Code for this demo
import { createGrid, type ColumnDef, type PrintOptions } from '@freegridjs/core';
import { HEADERS, makeRows } from '../data';
import { button, select, separator, text, toggle, tr, type DemoContext } from '../ui';
export default function mount(ctx: DemoContext) {
const { lang } = ctx;
const h = (en: string, ko: string) => tr(lang, { en, ko });
const t = HEADERS[lang];
const columns: ColumnDef[] = [
{ field: 'name', header: t.name, width: 150 },
{ field: 'country', header: t.country, width: 130 },
{ field: 'company', header: t.company, width: 130 },
{ header: t.revenue, children: [
{ field: 'q1', header: t.q1, type: 'number', format: '#,##0', width: 100 },
{ field: 'q2', header: t.q2, type: 'number', format: '#,##0', width: 100 },
] },
{ field: 'growth', header: t.growth, type: 'number', format: '0.0%', width: 90,
cellClass: p => (typeof p.value === 'number' && p.value < 0 ? 'neg' : 'pos') },
{ field: 'active', header: t.active, type: 'boolean', width: 70 },
{ field: 'joined', header: t.joined, type: 'date', width: 110 },
];
const grid = createGrid(ctx.host, {
columns, data: makeRows(60), locale: lang, rowNumbers: true,
});
// what the buttons below change
const opts: PrintOptions = {
title: h('Sales, first half of 2026', '2026년 상반기 매출 현황'),
subtitle: h('By country · Q1 and Q2', '국가별 · 1~2분기'),
footer: h('ACME Inc. · Internal use only', '(주)에이크미 · 대외비'),
paper: 'A4',
orientation: 'auto',
};
// the page print() would print, shown under the grid
const preview = document.createElement('iframe');
preview.className = 'print-preview';
preview.title = h('Print preview', '인쇄 미리보기');
preview.setAttribute('sandbox', '');
ctx.host.after(preview);
// a little padding stands in for the paper margins
const refresh = () => { preview.srcdoc = grid.getPrintHtml(opts).replace('<body>', '<body style="padding:24px 28px">'); };
grid.on('sortChange', refresh);
grid.on('filterChange', refresh);
refresh();
text(ctx, h('Column groups, colours and row numbers print as they are; the preview below updates as you sort, filter or change the options.',
'다단 헤더·색·행 번호가 그대로 인쇄됩니다. 정렬·필터나 옵션을 바꾸면 아래 미리보기가 바로 바뀝니다.'));
separator(ctx);
button(ctx, h('Print', '인쇄하기'), () => grid.print(opts));
select(ctx, h('Paper', '용지'), [['A4', 'A4'], ['A3', 'A3'], ['B4', 'B4'], ['letter', 'Letter']], 'A4', v => { opts.paper = v; refresh(); });
select(ctx, h('Direction', '방향'), [['auto', h('Auto', '자동')], ['portrait', h('Portrait', '세로')], ['landscape', h('Landscape', '가로')]], 'auto',
v => { opts.orientation = v; refresh(); });
separator(ctx);
toggle(ctx, h('Row numbers', '행 번호'), true, on => { opts.rowNumbers = on; refresh(); });
toggle(ctx, h('Stripes', '줄무늬'), true, on => { opts.striped = on; refresh(); });
toggle(ctx, h('Page numbers', '페이지 번호'), true, on => { opts.pageNumbers = on; refresh(); });
separator(ctx);
// headers print on every page; repeatRows adds the first rows too, repeatTitle the title block
toggle(ctx, h('Header on every page', '페이지마다 헤더'), true, on => { opts.repeatHeader = on; refresh(); });
select(ctx, h('Repeat rows', '반복할 행'), [['0', h('None', '없음')], ['1', '1'], ['2', '2'], ['3', '3']], '0', v => { opts.repeatRows = Number(v); refresh(); });
toggle(ctx, h('Title on every page', '페이지마다 제목'), false, on => { opts.repeatTitle = on; refresh(); });
return grid;
}print() prints the rows as they are on screen, with the current sort and filters, as a table on the paper you choose. Column groups, cellClass colours and row numbers print as they are; columns keep their proportions on the page, and wide grids turn the page sideways (orientation: 'auto'). A title, a subtitle and a footer go on the page, with page numbers and the time of printing. getPrintHtml() returns the page as HTML, for a preview like the one in the demo.
Printing stops at maxRows rows (1,000 by default), because a browser takes minutes to lay out a print of many thousands of rows; a note at the end says how many were printed. Pass a larger number (or Infinity) when you need more, or export to CSV, which has no limit.
Rows repeated on every page
Long tables repeat the column headers on every page (repeatHeader, on by default). Like a spreadsheet's "rows to repeat at top", repeatRows repeats the first rows as well, and repeatTitle: true repeats the title.
grid.print({
title: 'Sales, first half of 2026',
subtitle: 'By country · Q1 and Q2',
footer: 'ACME Inc. · Internal use only',
paper: 'A4', // A3, A5, B4, B5, letter, legal
orientation: 'auto', // sideways when the columns are wide
repeatHeader: true, // header rows on every page (default)
repeatRows: 1, // and the first row (e.g. last year's total) too
repeatTitle: false, // the title on the first page only
maxRows: 1000, // rows printed at most (default); a note says how many were left out
});
const html = grid.getPrintHtml({ title: 'Preview' }); // the HTML that prints (for a preview)The same layout can be saved as a PDF file, and Excel files can repeat rows on printed pages too; both are on Excel and PDF export.
Options
| Name | Type | Description |
|---|---|---|
title / subtitle / footer | string | Heading on top, a line under it, text at the bottom left of every page. |
paper / orientation | 'A4' | 'A3' | 'A5' | 'B4' | 'B5' | 'letter' | 'legal' / 'auto' | 'portrait' | 'landscape' | Default A4 and 'auto' (sideways when the columns are too wide). |
repeatHeader | boolean | Column headers on every page (default true). |
repeatRows | number | Also repeat the first n rows on every page, under the headers. |
repeatTitle | boolean | The title block on every page, not only the first. |
maxRows | number | Most data rows to print (default 1000); a note at the end says how many were left out. |
fitToWidth / groups / summary / striped / pageNumbers / printedAt / rowNumbers | boolean | Scale columns to the page, group rows with totals, summary rows, stripes, "1 / 3", print time, a # column. |
Questions about this page
How do I print a FreeGrid grid?
Call grid.print({ title, paper, orientation }). It prints the rows with the current sort and filters, and getPrintHtml() returns the same page for a preview.
How do I repeat the header row on every printed page?
Headers repeat by default (repeatHeader). repeatRows: n also repeats the first n rows, and repeatTitle repeats the title.