# 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:** vue  **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/vue/grid-pdf-export-template.json
```

**Install Package(s)**

```bash
npm install @syncfusion/ej2-vue-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.vue

```vue
<template>
<div class="col-lg-12">
  <div class="control-section">
    <ejs-grid ref="grid" id="PdfExportTemplateGrid" :dataSource="data" height="440" :rowHeight="60" :allowPaging="true" :pageSettings="pageSettings"
      gridLines="Horizontal" :allowPdfExport="true" :toolbar="toolbar" :toolbarClick="toolbarClick" :pdfQueryCellInfo="pdfQueryCellInfo">
      <e-columns>
        <e-column field="OrderID" headerText="Order" width="110" :isPrimaryKey="true"></e-column>
        <e-column field="CustomerName" headerText="Customer" width="250" :template="'customerTemplate'"></e-column>
        <e-column field="ShipCity" headerText="City" width="150"></e-column>
        <e-column headerText="Status" width="150" :template="'statusTemplate'"></e-column>
        <e-column field="Freight" headerText="Freight" width="120" format="C2" textAlign="Right"></e-column>
      </e-columns>
      <template v-slot:customerTemplate="{ data }">
        <div style="display:flex;align-items:center;gap:12px">
          <span :style="{ background: color(data.CustomerID) }" style="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(data.CustomerName) }}</span>
          <div style="display:flex;flex-direction:column;justify-content:center">
            <span style="display:block;font-weight:600;color:#0f172a;line-height:20px">{{ data.CustomerName }}</span>
            <span style="display:block;font-size:12px;color:#94a3b8;line-height:16px">{{ data.CustomerID }}</span>
          </div>
        </div>
      </template>
      <template v-slot:statusTemplate="{ data }">
        <span :style="{ background: status(data).bg, color: status(data).color }" style="border-radius:999px;padding:2px 10px;font-size:12px;font-weight:600">{{ status(data).label }} · {{ days(data) }}d</span>
      </template>
    </ejs-grid>
  </div>
</div>
</template>

<script lang="ts">
import { GridComponent, ColumnDirective, ColumnsDirective, Page, Toolbar, PdfExport } from "@syncfusion/ej2-vue-grids";
import { orderData } from '../datasource/grid-data';

const palette = ['#6366f1', '#0ea5e9', '#10b981', '#f59e0b', '#ec4899', '#8b5cf6'];
const daysOf = (o: any) => Math.max(0, Math.round((new Date(o.ShippedDate).getTime() - new Date(o.OrderDate).getTime()) / 86400000));
const statusOf = (o: any) => {
  const d = daysOf(o);
  return d <= 5 ? { label: 'Fast', color: '#059669', bg: '#d1fae5' }
    : d <= 10 ? { label: 'On time', color: '#0369a1', bg: '#e0f2fe' }
    : { label: 'Delayed', color: '#b45309', bg: '#fef3c7' };
};

export default {
  components: { 'ejs-grid': GridComponent, 'e-column': ColumnDirective, 'e-columns': ColumnsDirective },
  data: function() {
    return { data: orderData, pageSettings: { pageSize: 8 }, toolbar: ['PdfExport'] };
  },
  methods: {
    color: (text: string) => palette[[...text].reduce((s, c) => s + c.charCodeAt(0), 0) % palette.length],
    initials: (name: string) => name.trim().split(/\s+/).map(p => p[0]).slice(0, 2).join('').toUpperCase(),
    days: daysOf,
    status: statusOf,
    toolbarClick: function(args: any) {
      if (args.item.id === 'PdfExportTemplateGrid_pdfexport') {
        ((this as any).$refs.grid as any).ej2Instances.pdfExport({ fileName: 'Orders.pdf' });
      }
    },
    // Templates are HTML-only, so give the PDF plain text for each templated column.
    pdfQueryCellInfo: function(args: any) {
      const d = args.data;
      if (args.column.field === 'CustomerName') args.value = `${d.CustomerName} (${d.CustomerID})`;
      if (args.column.headerText === 'Status') args.value = `${statusOf(d).label} - ${daysOf(d)} days`;
    }
  },
  provide: { grid: [Page, Toolbar, PdfExport] }
}
</script>
```
