|
1 | 1 | import * as React from 'react'; |
2 | | -import './App.css'; |
| 2 | +import { createRoot } from 'react-dom/client'; |
3 | 3 | import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet'; |
4 | 4 | import { getDefaultData } from './data'; |
5 | 5 |
|
6 | | -function App() { |
7 | | - const spreadsheetRef = React.useRef<SpreadsheetComponent>(null); |
| 6 | +function App(): React.ReactElement { |
| 7 | + const spreadsheetRef = React.useRef<SpreadsheetComponent | null>(null); |
8 | 8 |
|
9 | 9 | const actionBegin = (args: any): void => { |
10 | | - const action = args?.action; |
11 | | - const eventArgs = args?.eventArgs; |
| 10 | + const action: string = args.action; |
| 11 | + const eventArgs: any= args.args.eventArgs; |
12 | 12 |
|
13 | 13 | // Check the action is beforeReplaceAll. |
14 | 14 | if (action === 'beforeReplaceAll') { |
15 | | - // Check the mode is Sheet. |
16 | | - if (eventArgs?.mode === 'Sheet') { |
17 | | - const spreadsheet = spreadsheetRef.current; |
18 | | - if (!spreadsheet) return; |
19 | | - |
20 | | - // Get the active sheet's selected range. |
21 | | - const selectedRange: string | undefined = spreadsheet.getActiveSheet()?.selectedRange; |
22 | | - if (!selectedRange) return; |
23 | | - |
24 | | - // Convert the selected range into cell collection. |
25 | | - const selectedRangeCollection: string[] = generateCellCollection(selectedRange, spreadsheet); |
26 | | - const replaceAllCollection: Array<string | null> = eventArgs.addressCollection as Array<string | null>; |
27 | | - if (!Array.isArray(replaceAllCollection)) return; |
28 | | - |
29 | | - // Create a Set from selectedRangeCollection for efficient lookup. |
30 | | - const selectedSet = new Set(selectedRangeCollection); |
31 | | - const updatedCollection: Array<string | null> = []; |
32 | | - |
33 | | - // Iterate through replaceAllCollection and keep only cells within selection. |
34 | | - for (const cell of replaceAllCollection) { |
35 | | - if (cell && selectedSet.has(cell)) { |
36 | | - updatedCollection.push(cell); |
37 | | - } else { |
38 | | - // If the cell is not in selectedRangeCollection, add null to the updated collection |
39 | | - updatedCollection.push(null); |
40 | | - } |
| 15 | + const spreadsheet = spreadsheetRef.current; |
| 16 | + if (!spreadsheet) return; |
| 17 | + |
| 18 | + // Get the active sheet's selected range. |
| 19 | + const selectedRange: string | undefined = spreadsheet.getActiveSheet()?.selectedRange; |
| 20 | + if (!selectedRange) return; |
| 21 | + |
| 22 | + // Convert the selected range into cell collection. |
| 23 | + const selectedRangeCollection: string[] = generateCellCollection(selectedRange, spreadsheet); |
| 24 | + const replaceAllCollection: Array<string | null> = eventArgs.addressCollection as Array<string | null>; |
| 25 | + if (!Array.isArray(replaceAllCollection)) return; |
| 26 | + |
| 27 | + // Create a Set from selectedRangeCollection for efficient lookup. |
| 28 | + const selectedSet: Set<string> = new Set<string>(selectedRangeCollection); |
| 29 | + const updatedCollection: Array<string | null> = []; |
| 30 | + |
| 31 | + // Iterate through replaceAllCollection and keep only cells within selection. |
| 32 | + for (const cell of replaceAllCollection) { |
| 33 | + if (cell && selectedSet.has(cell)) { |
| 34 | + updatedCollection.push(cell); |
| 35 | + } else { |
| 36 | + // If the cell is not in selectedRangeCollection, add null to the updated collection |
| 37 | + updatedCollection.push(null); |
41 | 38 | } |
| 39 | + } |
42 | 40 |
|
43 | | - if (updatedCollection.length > 0) { |
44 | | - // Assign the newly created cell collection to the addressCollection of replaceAll action. |
45 | | - eventArgs.addressCollection = updatedCollection; |
46 | | - } |
| 41 | + if (updatedCollection.length > 0) { |
| 42 | + // Assign the newly created cell collection to the addressCollection of replaceAll action. |
| 43 | + eventArgs.addressCollection = updatedCollection; |
47 | 44 | } |
48 | 45 | } |
49 | 46 | }; |
|
0 commit comments