Print the whole Vue Data Grid — every sorted and filtered row, not the twenty the virtualizer has on screen or the page the user happens to be on.
Printing a virtualized grid straight from the browser prints the twenty rows that happen to be in the DOM, and a paginated one prints the current page. Neither is what anyone means by “print this table”, so the grid renders a plain, complete table, prints that, and throws it away.
Enable the toolbar action with :toolbar="{ print: true }", or call printGrid()` from `@coreui/data-grid/print from your own
button. Search the grid below, then print: the printout carries every matching
row, not just the visible ones.
<script setup lang="ts">
import { CDataGrid } from '@coreui/vue-data-grid'
const columns = [
{ key: 'name', label: 'Name' },
{ key: 'role', label: 'Role' },
{ key: 'country', label: 'Country' }
]
const items = Array.from({ length: 60 }, (_, index) => ({
name: `Person ${index + 1}`,
role: index % 3 === 0 ? 'admin' : 'user',
country: ['Poland', 'Germany', 'Spain', 'Italy'][index % 4]
}))
</script>
<template>
<CDataGrid
:columns="columns"
:items="items"
:toolbar="{ print: true, search: true }"
global-filter
print-title="Team roster"
/>
</template>What gets printed
- Every sorted and filtered row. Pagination and virtualization are display concerns; the printout is the whole result set the user’s sorting, filters and search produced.
- The visible columns, in their current order — hidden and reordered columns follow what is on screen.
- Values as displayed. A column’s
formatterruns first, so a formatted date prints as the date on screen. - The
print-titleas a heading above the table, when set.
Custom cell renderers are not carried into the printout: it is built from values as text, never from markup, so the printed page can never become an injection surface for the data.
Options
| Option | Type | Default | Description |
|---|---|---|---|
toolbar.print | boolean | false | Adds the print button to the built-in toolbar. |
print-title | string | — | Heading printed above the table. |
toolbar-print-icon | `VNode | () => VNode` | printer |
Styling the printout
The clone is a .data-grid-print-root element appended to the document, and the
print stylesheet hides everything else on the page while it is there. Restyle it
like any other markup:
@media print {
.data-grid-print-root h1 { font-size: 1rem; }
.data-grid-print-root :is(th, td) { border-color: #999; }
}