This repository was archived by the owner on Jul 30, 2025. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathdefault-exporting.tsx
More file actions
73 lines (71 loc) · 3.98 KB
/
default-exporting.tsx
File metadata and controls
73 lines (71 loc) · 3.98 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
import * as ReactDOM from 'react-dom';
import * as React from 'react';
import { GridComponent, ColumnsDirective, ColumnDirective, Inject, Page, Toolbar, ExcelExport, PdfExport, Group } from '@syncfusion/ej2-react-grids';
import { orderDetails } from './data';
import { ClickEventArgs } from '@syncfusion/ej2-navigations'
import { SampleBase } from '../common/sample-base';
let refresh: Boolean;
export class Exporting extends SampleBase<{}, {}> {
public toolbarOptions: any = ['ExcelExport', 'PdfExport', 'CsvExport'];
public groupOptions: Object = { showDropArea : false , columns: ['ShipCountry'] };
private gridInstance: GridComponent;
public dataBound() {
if (refresh) {
this.gridInstance.groupColumn('ShipCountry');
refresh = false;
}
}
public load() {
refresh = (this as any).refreshing;
}
public toolbarClick(args: ClickEventArgs): void {
switch (args.item.text) {
case 'PDF Export':
this.gridInstance.pdfExport();
break;
case 'Excel Export':
this.gridInstance.excelExport();
break;
case 'CSV Export':
this.gridInstance.csvExport();
break;
}
}
render() {
return (
<div className='control-pane'>
<div className='control-section'>
<GridComponent dataSource={orderDetails} ref={ grid => this.gridInstance = grid} toolbar={this.toolbarOptions} allowPaging={true}
allowExcelExport={true} allowPdfExport={true} allowGrouping={true} toolbarClick={this.toolbarClick.bind(this)} groupSettings={this.groupOptions}
dataBound={this.dataBound.bind(this)} load={this.load}>
<ColumnsDirective>
<ColumnDirective field='OrderID' headerText='Order ID' width='120' textAlign='Right'></ColumnDirective>
<ColumnDirective field='CustomerID' headerText='Customer ID' width='150'></ColumnDirective>
<ColumnDirective field='OrderDate' headerText='Order Date' width='150' format='yMd' textAlign='Right'></ColumnDirective>
<ColumnDirective field='Freight' headerText='Freight' width='120' format='C2' textAlign='Right' ></ColumnDirective>
<ColumnDirective field='ShipCountry' headerText='Ship Country' width='150' ></ColumnDirective>
</ColumnsDirective>
<Inject services={[Page, Toolbar, ExcelExport, PdfExport, Group]} />
</GridComponent>
<div id="action-description">
<p>This sample demonstrates the client-side exporting of the Grid, which allows you to export its data to the Excel, Pdf and CSV formats.
Use the toolbar buttons to export Grid data to desired format.</p>
</div>
<div id="description">
<p>Grid supports client-side exporting which allows you to export its data to the Excel, Pdf and CSV formats.</p>
<p>In this demo, Grouping is applied for <strong><i>ShipCountry</i></strong> column and excelexport, pdfexport and csvexport items are defined in the toolbar. For these toolbar items, we have
defined actions in toolbarClick event to export the Grid data using the
<code><a target="_blank" className="code"
href="http://ej2.syncfusion.com/react/documentation/grid/api-gridComponent.html#excelexport">excelExport</a></code>,
<code><a target="_blank" className="code"
href="http://ej2.syncfusion.com/react/documentation/grid/api-gridComponent.html#pdfexport">pdfExport</a></code> and <code><a target="_blank" className="code"
href="http://ej2.syncfusion.com/react/documentation/grid/api-gridComponent.html#csvexport">csvExport</a></code> methods.</p>
<p style={{ fontWeight: 500 }}>Injecting Module:</p>
<p>Grid features are segregated into individual feature-wise modules. To use exporting feature, we need to inject <code>ExcelExport</code>
and <code>PdfExport</code> module into the <code>services</code></p>
</div>
</div>
</div>
)
}
}