React Common - Object Structures - PdfExportDataGridProps
Properties that can be passed as a parameter to the exportDataGrid(options) method from the pdfExporter module.
The exportDataGrid(options) method requires the jsPDF v2.3.1+ library to export data and create PDF files.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import DataGrid from 'devextreme-react/data-grid';
- import Button from 'devextreme-react/button';
- import { jsPDF } from 'jspdf';
- import { exportDataGrid as exportDataGridToPdf } from 'devextreme/pdf_exporter';
- export default function App() {
- const dataGridRef = useRef(null);
- function exportGrid() {
- const doc = new jsPDF();
- const dataGrid = dataGridRef.current.instance();
- exportDataGridToPdf({
- jsPDFDocument: doc,
- component: dataGrid
- }).then(() => {
- doc.save('Customers.pdf');
- });
- }
- return (
- <React.Fragment>
- <div>
- <Button ...
- onClick={exportGrid}
- />
- <DataGrid ...
- ref={dataGridRef}
- >
- {/* ... */}
- </DataGrid>
- </div>
- </React.Fragment>
- );
- }
columnWidths
Uses the measure units that are specified in the constructor of the jsPDFDocument object.
The example below calls the exportDataGrid(options) method on a button click. This method applies specific widths to the grid columns.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import DataGrid from 'devextreme-react/data-grid';
- import Button from 'devextreme-react/button';
- import { jsPDF } from 'jspdf';
- import { exportDataGrid as exportDataGridToPdf } from 'devextreme/pdf_exporter';
- export default function App() {
- const dataGridRef = useRef(null);
- function exportGrid() {
- const doc = new jsPDF();
- const dataGrid = dataGridRef.current.instance();
- exportDataGridToPdf({
- jsPDFDocument: doc,
- component: dataGrid,
- columnWidths: [50, 40, 40, 40]
- }).then(() => {
- doc.save('Customers.pdf');
- });
- }
- return (
- <React.Fragment>
- <div>
- <Button ...
- onClick={exportGrid}
- />
- <DataGrid ...
- ref={dataGridRef}
- >
- {/* ... */}
- </DataGrid>
- </div>
- </React.Fragment>
- );
- }
customDrawCell
A function that allows you to draw cell content of the exported DataGrid. This function is executed before the cell is exported.
Name | Type | Description |
---|---|---|
cancel |
Allows you to prevent default drawing logic. |
|
doc |
An instance of the jsPDFDocument object. |
|
gridCell |
A DataGrid cell. |
|
pdfCell |
An object that describes a cell in a PDF file. |
|
rect |
An object that contains information about the location of the cell and its dimensions. The object has the following structure: { x: numeric, y: numeric, h: numeric, w: numeric }. |
In the following example, this function adds an image to a cell:
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import DataGrid from 'devextreme-react/data-grid';
- import Button from 'devextreme-react/button';
- import { jsPDF } from 'jspdf';
- import 'jspdf-autotable';
- import { exportDataGrid as exportDataGridToPdf } from 'devextreme/pdf_exporter';
- const App = () => {
- const dataGridRef = useRef(null);
- function exportGrid() {
- const doc = new jsPDF();
- const dataGrid = dataGridRef.current.instance();
- exportDataGridToPdf({
- jsPDFDocument: doc,
- component: dataGrid,
- customDrawCell: (e) => {
- if (e.gridCell.rowType === 'data' && e.gridCell.column.dataField === 'Picture') {
- doc.addImage(e.gridCell.value, 'PNG', e.rect.x, e.rect.y, e.rect.w, e.rect.h);
- e.cancel = true;
- }
- },
- }).then(() => {
- doc.save('Customers.pdf');
- });
- }
- return (
- <React.Fragment>
- <Button ...
- onClick={exportGrid}
- />
- <DataGrid ...
- ref={dataGridRef}>
- {/* ... */}
- </DataGrid>
- </React.Fragment>
- );
- }
- export default App;
customizeCell
Name | Type | Description |
---|---|---|
gridCell |
A DataGrid cell. |
|
pdfCell |
An object that describes a cell in a PDF file. |
In the following example, this function changes the font size of the 'data' group row cells:
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import DataGrid from 'devextreme-react/data-grid';
- import Button from 'devextreme-react/button';
- import { jsPDF } from 'jspdf';
- import 'jspdf-autotable';
- import { exportDataGrid as exportDataGridToPdf } from 'devextreme/pdf_exporter';
- const App = () => {
- const dataGridRef = useRef(null);
- function exportGrid() {
- const doc = new jsPDF();
- const dataGrid = dataGridRef.current.instance();
- exportDataGridToPdf({
- jsPDFDocument: doc,
- component: dataGrid,
- customizeCell: function(options) {
- const { gridCell, pdfCell } = options;
- if(gridCell.rowType === 'data') {
- pdfCell.font = { size: 20 };
- }
- }
- }).then(() => {
- doc.save('Customers.pdf');
- });
- }
- return (
- <React.Fragment>
- <Button ...
- onClick={exportGrid}
- />
- <DataGrid ...
- ref={dataGridRef}>
- {/* ... */}
- </DataGrid>
- </React.Fragment>
- );
- }
- export default App;
See Also
- pdfExporter.exportDataGrid(options)
indent
This property uses the measure units that are specified in the constructor of the jsPDFDocument object.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import DataGrid from 'devextreme-react/data-grid';
- import Button from 'devextreme-react/button';
- import { jsPDF } from 'jspdf';
- import { exportDataGrid as exportDataGridToPdf } from 'devextreme/pdf_exporter';
- export default function App() {
- const dataGridRef = useRef(null);
- function exportGrid() {
- const doc = new jsPDF();
- const dataGrid = dataGridRef.current.instance();
- exportDataGridToPdf({
- jsPDFDocument: doc,
- component: dataGrid,
- indent: 15
- }).then(() => {
- doc.save('Customers.pdf');
- });
- }
- return (
- <React.Fragment>
- <div>
- <Button ...
- onClick={exportGrid}
- />
- <DataGrid ...
- ref={dataGridRef}
- >
- {/* ... */}
- </DataGrid>
- </div>
- </React.Fragment>
- );
- }
jsPDFDocument
A jsPDF instance. This setting is required.
loadPanel
The example below calls the exportDataGrid(options) method on a button click. This method enables the load panel and applies shading to the grid.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import DataGrid from 'devextreme-react/data-grid';
- import Button from 'devextreme-react/button';
- import { jsPDF } from 'jspdf';
- import { exportDataGrid as exportDataGridToPdf } from 'devextreme/pdf_exporter';
- export default function App() {
- const dataGridRef = useRef(null);
- function exportGrid() {
- const doc = new jsPDF();
- const dataGrid = dataGridRef.current.instance();
- exportDataGridToPdf({
- jsPDFDocument: doc,
- component: dataGrid,
- loadPanel: {
- enabled: true,
- shading: true,
- shadingColor: "#808080"
- }
- }).then(() => {
- doc.save('Customers.pdf');
- });
- }
- return (
- <React.Fragment>
- <div>
- <Button ...
- onClick={exportGrid}
- />
- <DataGrid ...
- ref={dataGridRef}
- >
- {/* ... */}
- </DataGrid>
- </div>
- </React.Fragment>
- );
- }
margin
Uses the measure units that are specified in the constructor of the jsPDFDocument object.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import DataGrid from 'devextreme-react/data-grid';
- import Button from 'devextreme-react/button';
- import { jsPDF } from 'jspdf';
- import 'jspdf-autotable';
- import { exportDataGrid as exportDataGridToPdf } from 'devextreme/pdf_exporter';
- const App = () => {
- const dataGridRef = useRef(null);
- function exportGrid() {
- const doc = new jsPDF();
- const dataGrid = dataGridRef.current.instance();
- exportDataGridToPdf({
- margin: { top: 20, right: 20, bottom: 20, left: 20 },
- jsPDFDocument: doc,
- component: dataGrid,
- }).then(() => {
- doc.save('Customers.pdf');
- });
- }
- return (
- <React.Fragment>
- <Button ...
- onClick={exportGrid}
- />
- <DataGrid ...
- ref={dataGridRef}>
- {/* ... */}
- </DataGrid>
- </React.Fragment>
- );
- }
- export default App;
See Also
- pdfExporter.exportDataGrid(options)
onRowExporting
A function that allows you to customize the height of the exported row. This function is executed before the row export.
- import React from 'react';
- import 'devextreme/dist/css/dx.light.css';
- import DataGrid from 'devextreme-react/data-grid';
- import Button from 'devextreme-react/button';
- import { jsPDF } from 'jspdf';
- import 'jspdf-autotable';
- import { exportDataGrid as exportDataGridToPdf } from 'devextreme/pdf_exporter';
- const App = () => {
- const dataGridRef = useRef(null);
- function exportGrid() {
- const doc = new jsPDF();
- const dataGrid = dataGridRef.current.instance();
- exportDataGridToPdf({
- jsPDFDocument: doc,
- component: dataGrid,
- onRowExporting: (e) => {
- e.rowHeight = 20;
- },
- }).then(() => {
- doc.save('Customers.pdf');
- });
- }
- return (
- <React.Fragment>
- <Button ...
- onClick={exportGrid}
- />
- <DataGrid ...
- ref={dataGridRef}>
- {/* ... */}
- </DataGrid>
- </React.Fragment>
- );
- }
- export default App;
topLeft
Specifies the top left position of the DataGrid in the exported PDF document. Contains x and y properties. You can locate this position only below the page margins.
If you have technical questions, please create a support ticket in the DevExpress Support Center.