-
Notifications
You must be signed in to change notification settings - Fork 6
/
Copy pathApp.tsx
102 lines (91 loc) · 3.27 KB
/
App.tsx
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
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
// Import necessary hooks and components from React and Ag-Grid
import { useCallback, useMemo, useState } from 'react';
import { AgGridReact } from '@ag-grid-community/react';
import useStyles from '@equinor/fusion-react-ag-grid-styles';
import { ColDef, ModuleRegistry } from '@ag-grid-community/core';
// Import required Ag-Grid modules
import { ClientSideRowModelModule } from '@ag-grid-community/client-side-row-model';
import { ColumnsToolPanelModule } from '@ag-grid-enterprise/column-tool-panel';
import { FiltersToolPanelModule } from '@ag-grid-enterprise/filter-tool-panel';
import { MenuModule } from '@ag-grid-enterprise/menu';
import { ExcelExportModule } from '@ag-grid-enterprise/excel-export';
import { ClipboardModule } from '@ag-grid-enterprise/clipboard';
// Import custom table configuration
import { defaultColDef, sideBar } from './table';
// Register Ag-Grid modules
ModuleRegistry.registerModules([
ClientSideRowModelModule,
ColumnsToolPanelModule,
FiltersToolPanelModule,
MenuModule,
ExcelExportModule,
ClipboardModule,
]);
// Define the type for the row data
export type RowDataType = {
make: string;
model: string;
price: number;
};
export const App = (): JSX.Element => {
// Use custom styles for the grid
useStyles();
// Define the grid style
const gridStyle = useMemo(() => ({ height: '600px', width: '100%' }), []);
// Initialize state for the row data
const [rowData, setRowData] = useState<RowDataType[]>([]);
// Define column definitions with useMemo
const columnDefs = useMemo<ColDef[]>(() => {
return [
{
field: 'make',
headerCheckboxSelection: true,
checkboxSelection: true,
showDisabledCheckboxes: true,
},
{ field: 'model' },
{ field: 'price' },
];
}, []);
// Define a function to add a new row
const addRow = useCallback(() => {
setRowData([
...rowData,
{
make: 'Lada',
model: `Turbo x ${rowData.length}`,
price: 53200 + rowData.length,
},
]);
}, [rowData, setRowData]);
// Define a function to set initial grid data when the grid is ready
const onGridReady = useCallback(() => {
setRowData([
{ make: 'Toyota', model: 'Celica', price: 35000 },
{ make: 'Ford', model: 'Mondeo', price: 32000 },
{ make: 'Porsche', model: 'Boxster', price: 72000 },
]);
}, []);
return (
<>
<div>
<h4>Hello Fusion-framework Ag-Grid</h4>
<button onClick={addRow}>Add Row</button>
</div>
<div style={gridStyle} className="ag-theme-alpine-fusion">
<AgGridReact
rowData={rowData}
columnDefs={columnDefs}
defaultColDef={defaultColDef}
sideBar={sideBar}
rowSelection={'multiple'}
copyHeadersToClipboard={true}
cellSelection={true}
allowContextMenuWithControlKey={true}
onGridReady={onGridReady}
/>
</div>
</>
);
};
export default App;