# grid-pdf-export-template

> Data grid with a PDF export toolbar action and a query cell callback so templated columns export as plain text.

**Framework:** javascript  **Component:** Grid  **Variant:** pdf-export-template

## Get this item

**If you are an agent, fetch the JSON.** Source is inlined, so one request is enough and no tooling is required:

```
GET https://ai.syncfusion.com/r/javascript/grid-pdf-export-template.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-grids
```

**Notes**

- Syncfusion release: 2026 Volume 3 (v35.1.37)
- The Syncfusion package is licensed. The composition in this file is source you own and edit. See https://ai.syncfusion.com/licensing.md

## Source files

### src/components/grid-pdf-export-template/grid.html

```html
<div class="control-section">
    <div class="content-wrapper">
        <div id="container"></div>
    </div>
</div>
```

### src/components/grid-pdf-export-template/grid.ts

```typescript
import { Grid, Page, Toolbar, PdfExport } from '@syncfusion/ej2-grids';
import { orderData } from '../datasource/grid-data';

Grid.Inject(Page, Toolbar, PdfExport);

const palette: string[] = ['#6366f1', '#0ea5e9', '#10b981', '#f59e0b', '#ec4899', '#8b5cf6'];

function prepare(): Object[] {
    return (orderData as any[]).map((o: any) => {
        const days: number = Math.max(0, Math.round((new Date(o.ShippedDate).getTime() - new Date(o.OrderDate).getTime()) / 86400000));
        const s = days <= 5 ? { label: 'Fast', color: '#059669', bg: '#d1fae5' }
            : days <= 10 ? { label: 'On time', color: '#0369a1', bg: '#e0f2fe' }
            : { label: 'Delayed', color: '#b45309', bg: '#fef3c7' };
        return {
            ...o,
            Initials: o.ShipName.trim().split(/\s+/).map((p: string) => p[0]).slice(0, 2).join('').toUpperCase(),
            Color: palette[[...o.CustomerID].reduce((sum: number, c: string) => sum + c.charCodeAt(0), 0) % palette.length],
            StatusLabel: s.label, Days: days,
            StatusText: s.label + ' · ' + days + 'd', StatusColor: s.color, StatusBg: s.bg
        };
    });
}

export function initPdfExportTemplateGrid(): void {
    const customerTemplate: string =
        '<div style="display:flex;align-items:center;gap:12px">' +
        '<span style="background:${Color};width:36px;height:36px;border-radius:12px;color:#fff;display:inline-flex;align-items:center;justify-content:center;font-weight:600;font-size:13px">${Initials}</span>' +
        '<div style="display:flex;flex-direction:column;justify-content:center">' +
        '<span style="display:block;font-weight:600;color:#0f172a;line-height:20px">${ShipName}</span>' +
        '<span style="display:block;font-size:12px;color:#94a3b8;line-height:16px">${CustomerID}</span></div></div>';
    const statusTemplate: string =
        '<span style="background:${StatusBg};color:${StatusColor};border-radius:999px;padding:2px 10px;font-size:12px;font-weight:600">${StatusText}</span>';

    const grid: Grid = new Grid({
        dataSource: prepare(),
        height: 440,
        rowHeight: 60,
        allowPaging: true,
        pageSettings: { pageSize: 8 },
        gridLines: 'Horizontal',
        allowPdfExport: true,
        toolbar: ['PdfExport'],
        toolbarClick: (args: any) => {
            if (args.item.id === grid.element.id + '_pdfexport') {
                grid.pdfExport({ fileName: 'Orders.pdf' });
            }
        },
        // Templates are HTML-only, so give the PDF plain text for each templated column.
        pdfQueryCellInfo: (args: any) => {
            const d: any = args.data;
            if (args.column.field === 'ShipName') { args.value = d.ShipName + ' (' + d.CustomerID + ')'; }
            if (args.column.headerText === 'Status') { args.value = d.StatusLabel + ' - ' + d.Days + ' days'; }
        },
        columns: [
            { field: 'OrderID', headerText: 'Order', width: 110, isPrimaryKey: true },
            { field: 'ShipName', headerText: 'Ship To', width: 250, template: customerTemplate },
            { field: 'ShipCity', headerText: 'City', width: 150 },
            { headerText: 'Status', width: 150, template: statusTemplate },
            { field: 'Freight', headerText: 'Freight', width: 120, format: 'C2', textAlign: 'Right' }
        ]
    });
    grid.appendTo('#container');
}
```
