-
Data Grid
- Overview
-
Data Binding
-
Paging and Scrolling
-
Editing
-
Grouping
-
Filtering and Sorting
- Focused Row
-
Row Drag & Drop
-
Selection
-
Columns
- State Persistence
-
Appearance
-
Templates
-
Data Summaries
-
Master-Detail
-
Export to PDF
-
Export to Excel
-
Adaptability
- Keyboard Navigation
-
Pivot Grid
- Overview
-
Data Binding
-
Field Chooser
-
Features
-
Export to Excel
-
Tree List
- Overview
-
Data Binding
- Sorting
- Paging
-
Editing
- Node Drag & Drop
- Focused Row
-
Selection
-
Filtering
-
Column Customization
- State Persistence
- Adaptability
- Keyboard Navigation
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Features
- Virtual Scrolling
-
Grouping
-
Customization
- Adaptability
-
Html Editor
-
Chat
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
Charts
- Overview
-
Data Binding
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Line Charts
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
-
Sparkline Charts
-
Tree Map
-
Funnel and Pyramid Charts
- Sankey Chart
-
Combinations
-
More Features
-
Export
-
Selection
-
Tooltips
-
Zooming
-
-
Gantt
- Overview
-
Data
-
UI Customization
- Strip Lines
- Export to PDF
- Sorting
-
Filtering
-
Gauges
- Overview
-
Data Binding
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Navigation
- Overview
- Accordion
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
- Pagination
-
Tree View
- Right-to-Left Support
-
Layout
-
Tile View
- Splitter
-
Gallery
- Scroll View
- Box
- Responsive Box
- Resizable
-
-
Editors
- Overview
- Autocomplete
-
Calendar
- Check Box
- Color Box
-
Date Box
-
Date Range Box
-
Drop Down Box
-
Number Box
-
Select Box
- Switch
-
Tag Box
- Text Area
- Text Box
- Validation
- Custom Text Editor Buttons
- Right-to-Left Support
- Editor Appearance Variants
-
Forms and Multi-Purpose
- Overview
- Button Group
- Field Set
-
Filter Builder
-
Form
- Radio Group
-
Range Selector
- Numeric Scale (Lightweight)
- Numeric Scale
- Date-Time Scale (Lightweight)
- Date-Time Scale
- Logarithmic Scale
- Discrete scale
- Custom Formatting
- Use Range Selection for Calculation
- Use Range Selection for Filtering
- Image on Background
- Chart on Background
- Customized Chart on Background
- Chart on Background with Series Template
- Range Slider
- Slider
-
Sortable
-
File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Actions and Lists
- Overview
-
Action Sheet
-
Button
- Floating Action Button
- Drop Down Button
-
Context Menu
-
List
-
Lookup
-
Maps
- Overview
-
Map
-
Vector Map
-
Dialogs and Notifications
-
Localization
React Pivot Grid - Header and Footer
The PivotGrid allows you to customize a header and a footer in the exported Excel file. The ExcelJS library allows you to customize worksheets outside of exported cell regions. This, in turns, allows you to add a header (a title before exported data) and a footer (a note after exported data).
If you have technical questions, please create a support ticket in the DevExpress Support Center.
import React, { useCallback, useState } from 'react';
import PivotGrid, {
FieldChooser,
FieldPanel,
Export,
PivotGridTypes,
} from 'devextreme-react/pivot-grid';
import CheckBox from 'devextreme-react/check-box';
import PivotGridDataSource from 'devextreme/ui/pivot_grid/data_source';
import { Workbook } from 'exceljs';
import { saveAs } from 'file-saver-es';
// Our demo infrastructure requires us to use 'file-saver-es'.
// We recommend that you use the official 'file-saver' package in your applications.
import { exportPivotGrid } from 'devextreme/excel_exporter';
import { sales } from './data.ts';
const dataSource = new PivotGridDataSource({
fields: [{
caption: 'Region',
width: 120,
dataField: 'region',
area: 'row',
expanded: true,
}, {
caption: 'City',
dataField: 'city',
width: 150,
area: 'row',
}, {
dataField: 'date',
dataType: 'date',
area: 'column',
filterValues: [[2013], [2014], [2015]],
expanded: false,
}, {
caption: 'Sales',
dataField: 'amount',
dataType: 'number',
summaryType: 'sum',
format: 'currency',
area: 'data',
}, {
caption: 'Country',
dataField: 'country',
area: 'filter',
}],
store: sales,
});
const App = () => {
const [exportDataFieldHeaders, setExportDataFieldHeaders] = useState(false);
const [exportRowFieldHeaders, setExportRowFieldHeaders] = useState(false);
const [exportColumnFieldHeaders, setExportColumnFieldHeaders] = useState(false);
const [exportFilterFieldHeaders, setExportFilterFieldHeaders] = useState(false);
const onExporting = useCallback((e: PivotGridTypes.ExportingEvent) => {
const workbook = new Workbook();
const worksheet = workbook.addWorksheet('Sales');
worksheet.columns = [
{ width: 30 }, { width: 20 }, { width: 30 }, { width: 30 }, { width: 30 }, { width: 30 },
];
exportPivotGrid({
component: e.component,
worksheet,
topLeftCell: { row: 4, column: 1 },
keepColumnWidths: false,
exportDataFieldHeaders,
exportRowFieldHeaders,
exportColumnFieldHeaders,
exportFilterFieldHeaders,
}).then((cellRange) => {
// Header
const headerRow = worksheet.getRow(2);
const worksheetViews: any = worksheet.views;
headerRow.height = 30;
const columnFromIndex = worksheetViews[0].xSplit + 1;
const columnToIndex = columnFromIndex + 3;
worksheet.mergeCells(2, columnFromIndex, 2, columnToIndex);
const headerCell = headerRow.getCell(columnFromIndex);
headerCell.value = 'Sales Amount by Region';
headerCell.font = { name: 'Segoe UI Light', size: 22, bold: true };
headerCell.alignment = { horizontal: 'left', vertical: 'middle', wrapText: true };
// Footer
const footerRowIndex = cellRange.to.row + 2;
const footerCell = worksheet.getRow(footerRowIndex).getCell(cellRange.to.column);
footerCell.value = 'www.wikipedia.org';
footerCell.font = { color: { argb: 'BFBFBF' }, italic: true };
footerCell.alignment = { horizontal: 'right' };
}).then(() => {
workbook.xlsx.writeBuffer().then((buffer) => {
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'Sales.xlsx');
});
});
}, [
exportColumnFieldHeaders,
exportDataFieldHeaders,
exportFilterFieldHeaders,
exportRowFieldHeaders,
]);
return (
<React.Fragment>
<div className="long-title">
<h3>Sales Amount by Region</h3>
</div>
<PivotGrid
dataSource={dataSource}
height={440}
showBorders={true}
allowSorting={true}
allowFiltering={true}
onExporting={onExporting}
>
<FieldPanel
showDataFields={true}
showRowFields={true}
showColumnFields={true}
showFilterFields={true}
allowFieldDragging={true}
visible={true}>
</FieldPanel>
<FieldChooser enabled={false} />
<Export enabled={true} />
</PivotGrid>
<div className="export-options">
<div className="caption">Export Options</div>
<div className="options">
<CheckBox id="export-data-field-headers"
value={exportDataFieldHeaders}
onValueChange={setExportDataFieldHeaders}
text="Export Data Field Headers" />
<CheckBox id="export-row-field-headers"
value={exportRowFieldHeaders}
onValueChange={setExportRowFieldHeaders}
text="Export Row Field Headers" />
<CheckBox id="export-column-field-headers"
value={exportColumnFieldHeaders}
onValueChange={setExportColumnFieldHeaders}
text="Export Column Field Headers" />
<CheckBox id="export-filter-field-headers"
value={exportFilterFieldHeaders}
onValueChange={setExportFilterFieldHeaders}
text="Export Filter Field Headers" />
</div>
</div>
</React.Fragment>
);
};
export default App;
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
xxxxxxxxxx
Follow the steps below to configure a header/footer:
-
In the onExporting event handler, call the exportPivotGrid(options) method.
-
Enable one or multiple options to export headers of the fields in the field panel:
-
Execute a promise after the exportPivotGrid(options) method. In this promise, specify the position, appearance, and content of the header/footer. The functions used to generate header and footer sections utilize the following PivotGrid customization features:
-
Cell values formatting
-
Text alignment