-
Data Grids / Data Management
-
Data Grid
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Grouping
-
Selection
- Focused Row
- Paging
-
Scrolling
-
Columns
-
Master-Detail
-
Data Summaries
-
Drag & Drop
-
Export to PDF
-
Export to Excel
- Appearance
-
Customization
- State Persistence
-
Adaptability
-
Keyboard Navigation
- Right-To-Left Support
-
Tree List
- Overview
-
Data Binding
-
Filtering
- Sorting
-
Editing
-
Selection
- Focused Row
- Paging
-
Columns
- Drag & Drop
- State Persistence
- Adaptability
-
Keyboard Navigation
-
Card View
-
Pivot Grid
- Overview
-
Data Binding
-
Field Management
-
Data Summaries
- Drill Down
- Filtering
-
Scrolling
-
Export to Excel
- Chart Integration
- Customization
- State Persistence
-
Filter Builder
-
-
Data Visualization
-
Charts
- Overview
-
Data Binding
-
Common Concepts
-
Axis
-
Aggregation
-
Tooltips
-
Selection
-
Customization
-
Zooming
-
Export
-
-
Area Charts
-
Bar Charts
- Bullet Charts
-
Doughnut Charts
-
Financial Charts
-
Funnel and Pyramid Charts
-
Line Charts
- Pareto Chart
-
Pie Charts
-
Point Charts
-
Polar and Radar Charts
-
Range Charts
- Sankey Chart
-
Sparkline Charts
-
Tree Map
-
Gauges
- Overview
-
Runtime update
-
Bar Gauge
-
Circular Gauge
-
Linear Gauge
-
Diagram
- Overview
-
Data Binding
-
Featured Shapes
-
Custom Shapes
-
Document Capabilities
-
User Interaction
- UI Customization
- Adaptability
-
-
Scheduling / Planning
-
Scheduler
- Overview
-
Data Binding
-
Views
-
Appointments
-
Timetable
- Editing
-
Grouping
- Virtual Scrolling
- Drag & Drop
-
Customization
- Adaptability
-
Gantt
- Overview
- Data Binding
-
Filtering
- Sorting
- Strip Lines
- Export to PDF
- Validation
-
Customization
-
-
Messaging
-
WYSIWYG Editor
-
Forms
-
Data Editors
- Overview
-
Common Concepts
-
Calendar
- Check Box
- Color Box
-
Date Box
-
Date Range Box
-
Number Box
- Radio Group
-
Range Selector
- Range Slider
- Slider
- Switch
- Text Area
- Text Box
-
Drop-Downs
- Autocomplete
-
Drop Down Box
-
Select Box
-
Tag Box
-
Lookup
-
Buttons
-
File Upload / File Management
-
File Manager
- Overview
-
File System Types
-
Customization
-
File Uploader
-
-
Popup and Notifications
-
Navigation
- Overview
- Accordion
-
Action Sheet
-
Context Menu
-
Menu
- Multi View
-
Drawer
-
Tab Panel
-
Tabs
-
Toolbar
-
Stepper
- Pagination
-
List
-
Tree View
- Right-to-Left Support
-
Layout
-
Interactive Wrappers
-
Sortable
- Resizable
-
-
Progress Indicators
-
Maps
- Overview
-
Map
-
Vector Map
-
Data Binding
- Multiple Layers
-
Markers
- Legend
-
Zooming and Panning
-
Customization
-
-
Localization
Related Demos:
Your search did not match any results.
JavaScript/jQuery Data Grid - Multiple Grids Export
The exportDataGrid() method allows users to export multiple grids to one Excel document. Grids are exported consequently in a chain of Promises.
In this demo, this functionality is used to export two DataGrids into separate worksheets in the same workbook. Starting position of each exported grid is set using the topLeftCell property.
Use the customizeCell method to customize the exported worksheets.
Backend API
$(() => {
const priceCaption = 'Price';
const ratingCaption = 'Rating';
$('#tabPanel').dxTabPanel({
dataSource: [{
title: priceCaption,
template() {
return $("<div id='priceDataGrid'>").dxDataGrid({
width: '100%',
columns: [
{ dataField: 'Product_ID', caption: 'ID', width: 50 },
{ dataField: 'Product_Name', caption: 'Name' },
{
dataField: 'Product_Sale_Price', caption: 'Sale Price', dataType: 'number', format: 'currency',
},
{
dataField: 'Product_Retail_Price', caption: 'Retail Price', dataType: 'number', format: 'currency',
},
],
showBorders: true,
rowAlternationEnabled: true,
dataSource: {
store: {
type: 'odata',
version: 2,
url: 'https://js.devexpress.com/Demos/DevAV/odata/Products',
key: 'Product_ID',
},
select: ['Product_ID', 'Product_Name', 'Product_Sale_Price', 'Product_Retail_Price'],
filter: ['Product_ID', '<', 10],
},
});
},
}, {
title: ratingCaption,
template() {
return $("<div id='ratingDataGrid'>").dxDataGrid({
width: '100%',
columns: [
{ dataField: 'Product_ID', caption: 'ID', width: 50 },
{ dataField: 'Product_Name', caption: 'Name' },
{ dataField: 'Product_Consumer_Rating', caption: 'Rating' },
{ dataField: 'Product_Category', caption: 'Category' },
],
showBorders: true,
rowAlternationEnabled: true,
dataSource: {
store: {
type: 'odata',
version: 2,
url: 'https://js.devexpress.com/Demos/DevAV/odata/Products',
key: 'Product_ID',
},
select: ['Product_ID', 'Product_Name', 'Product_Consumer_Rating', 'Product_Category'],
filter: ['Product_ID', '<', 10],
},
});
},
}],
itemTitleTemplate(itemData, itemIndex, itemElement) {
itemElement.append(`<span class='dx-tab-text'>${itemData.title}</span>`);
},
deferRendering: false,
});
$('#exportButton').dxButton({
text: 'Export multiple grids',
icon: 'xlsxfile',
onClick() {
const dataGrid1 = $('#priceDataGrid').dxDataGrid('instance');
const dataGrid2 = $('#ratingDataGrid').dxDataGrid('instance');
const workbook = new ExcelJS.Workbook();
const priceSheet = workbook.addWorksheet(priceCaption);
const ratingSheet = workbook.addWorksheet(ratingCaption);
priceSheet.getRow(2).getCell(2).value = 'Price';
priceSheet.getRow(2).getCell(2).font = { bold: true, size: 16, underline: 'double' };
ratingSheet.getRow(2).getCell(2).value = 'Rating';
ratingSheet.getRow(2).getCell(2).font = { bold: true, size: 16, underline: 'double' };
function setAlternatingRowsBackground(gridCell, excelCell) {
if (gridCell.rowType === 'header' || gridCell.rowType === 'data') {
if (excelCell.fullAddress.row % 2 === 0) {
excelCell.fill = {
type: 'pattern', pattern: 'solid', fgColor: { argb: 'D3D3D3' }, bgColor: { argb: 'D3D3D3' },
};
}
}
}
DevExpress.excelExporter.exportDataGrid({
worksheet: priceSheet,
component: dataGrid1,
topLeftCell: { row: 4, column: 2 },
customizeCell(options) {
setAlternatingRowsBackground(options.gridCell, options.excelCell);
},
}).then(() => DevExpress.excelExporter.exportDataGrid({
worksheet: ratingSheet,
component: dataGrid2,
topLeftCell: { row: 4, column: 2 },
customizeCell(options) {
setAlternatingRowsBackground(options.gridCell, options.excelCell);
},
})).then(() => {
workbook.xlsx.writeBuffer().then((buffer) => {
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'MultipleGrids.xlsx');
});
});
},
});
});
<!DOCTYPE html>
<html xmlns="http://www.w3.org/1999/xhtml" lang="en">
<head>
<title>DevExtreme Demo</title>
<meta http-equiv="X-UA-Compatible" content="IE=edge" />
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=5.0" />
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/babel-polyfill/7.12.1/polyfill.min.js"
integrity="sha384-FCwalFIn/oY5yqK5WoHWMqsdHAQgG5e8hoHwtQ/stzqubOMOvFXsWocs/XvlofdX"
crossorigin="anonymous"
></script>
<script
type="text/javascript"
src="https://cdn.jsdelivr.net/npm/devextreme-exceljs-fork@4.4.2/dist/dx-exceljs-fork.min.js"
integrity="sha384-0+mgPqjdXmZE1Htq8mACKhUtATn8hf01dRM9aFav8bXXD1ioy+B6TIu9lieIrTcM"
crossorigin="anonymous"
></script>
<script
type="text/javascript"
src="https://cdnjs.cloudflare.com/ajax/libs/FileSaver.js/2.0.5/FileSaver.min.js"
integrity="sha384-PlRSzpewlarQuj5alIadXwjNUX+2eNMKwr0f07ShWYLy8B6TjEbm7ZlcN/ScSbwy"
crossorigin="anonymous"
></script>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.5.1/jquery.min.js"></script>
<script>window.jQuery || document.write(decodeURIComponent('%3Cscript src="js/jquery.min.js"%3E%3C/script%3E'))</script>
<link rel="stylesheet" type="text/css" href="https://cdn3.devexpress.com/jslib/25.1.4/css/dx.light.css" />
<script src="js/dx.all.js?v=25.1.4"></script>
<link rel="stylesheet" type="text/css" href="styles.css" />
<script src="index.js"></script>
</head>
<body class="dx-viewport">
<div class="demo-container">
<div id="exportContainer">
<div id="exportButton"></div>
</div>
<div id="tabPanel"></div>
</div>
</body>
</html>
#priceDataGrid,
#ratingDataGrid {
padding: 10px;
}
#exportContainer {
text-align: right;
}
#tabPanel {
padding-top: 10px;
}