-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathApp.tsx
More file actions
51 lines (46 loc) · 1.44 KB
/
App.tsx
File metadata and controls
51 lines (46 loc) · 1.44 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
import { useCallback } from 'react';
import './App.css';
import 'devextreme/dist/css/dx.material.blue.light.compact.css';
import PivotGrid, {
FieldPanel,
FieldChooser,
Export,
} from 'devextreme-react/pivot-grid';
import type { PivotGridTypes } from 'devextreme-react/pivot-grid';
import { exportPivotGrid } from 'devextreme/excel_exporter';
import { Workbook } from 'devextreme-exceljs-fork';
import { saveAs } from 'file-saver';
import AdventureWorksService from './adventureworks.service';
const dataSource = AdventureWorksService.getPivotGridDataSource();
function App(): JSX.Element {
const exportGrid = useCallback((e: PivotGridTypes.ExportingEvent) => {
const workbook = new Workbook();
const worksheet = workbook.addWorksheet('Sales');
exportPivotGrid({
component: e.component,
worksheet,
}).then(() => workbook.xlsx.writeBuffer().then((buffer: ArrayBuffer) => {
saveAs(new Blob([buffer], { type: 'application/octet-stream' }), 'Sales.xlsx');
})).catch(() => undefined);
e.cancel = true;
}, []);
return (
<PivotGrid
id="pivot-grid"
dataSource={dataSource}
allowSorting={true}
allowSortingBySummary={true}
allowFiltering={true}
onExporting={exportGrid}>
<FieldPanel
visible={true}
showFilterFields={false}
/>
<FieldChooser
allowSearch={true}
/>
<Export enabled={true} />
</PivotGrid>
);
}
export default App;