Skip to content

Commit 1f346e7

Browse files
committed
1012637: updated How to session for react spreadsheet in ug documentation
1 parent 4e6bbf3 commit 1f346e7

10 files changed

Lines changed: 91 additions & 90 deletions

File tree

Document-Processing-toc.html

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -5314,9 +5314,9 @@
53145314
<li><a href="/document-processing/excel/spreadsheet/react/how-to/change-active-sheet">Changing the active sheet while importing a file</a></li>
53155315
<li><a href="/document-processing/excel/spreadsheet/react/how-to/identify-the-context-menu-opened">Identify the context menu opened</a></li>
53165316
<li><a href="/document-processing/excel/spreadsheet/react/how-to/find-replace-in-range">Find and replace the text within the selected range of cells</a></li>
5317-
<li><a href="/document-processing/excel/spreadsheet/react/how-to/add-dynamic-cell-template">Add dynamic cell templates in the spreadsheet</a></li>
5318-
<li><a href="/document-processing/excel/spreadsheet/react/how-to/add-cell-icon">Add an icon to the cell in the spreadsheet</a></li>
5319-
<li><a href="/document-processing/excel/spreadsheet/react/how-to/get-filtered-data">Get the filtered row data in a spreadsheet</a></li>
5317+
<li><a href="/document-processing/excel/spreadsheet/react/how-to/add-dynamic-cell-template">Add dynamic cell templates</a></li>
5318+
<li><a href="/document-processing/excel/spreadsheet/react/how-to/add-cell-icon">Add an icon to the cell</a></li>
5319+
<li><a href="/document-processing/excel/spreadsheet/react/how-to/get-filtered-data">Get the filtered row data</a></li>
53205320
</ul>
53215321
</li>
53225322
<li><a href="/document-processing/excel/spreadsheet/react/mobile-responsiveness">Mobile Responsiveness</a></li>

Document-Processing/Excel/Spreadsheet/React/how-to/add-dynamic-cell-template.md

Lines changed: 2 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,11 +9,9 @@ documentation: ug
99

1010
# Create Dynamic Cell Templates with Dropdowns in React Spreadsheet
1111

12-
In the Syncfusion Spreadsheet, you can add custom templates in cells. Before, cell templates were added by using the `template` property inside ranges, and templates were rendered through the `beforeCellRender` event.
12+
You can add templates to cells in the Syncfusion Spreadsheet component by dynamically assigning a custom template property directly to individual cells. When a cell has this custom template property, you can use the [beforeCellRender](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#beforecellrender) event to append the desired template element to the cell. You can initialize programmatically in the [created](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#created) event to apply templates to cells.
1313

14-
But you can apply custom templates by assigning a template name directly to a cell. During `beforeCellRender`, the Spreadsheet checks for this template and renders the template. Templates can be added when the sheet loads or applied to any selected cell.
15-
16-
The following sample shows how to add custom dropdown template in cells. It includes a custom Ribbon tab named template with a dropdown button. You can also initialize the templates to the cells. When the dropdown list button is clicked, the Spreadsheet dynamically applies the dropdown template to the currently active cell.
14+
The following sample demonstrates how to insert a [Syncfusion Dropdown component](https://www.npmjs.com/package/@syncfusion/ej2-dropdowns) into Spreadsheet cells using this custom template property. Additionally, a custom ribbon item named "DropDown List" is included under a new "Template" ribbon tab. When this ribbon item is selected, the Spreadsheet dynamically inserts a dropdown into the currently active cell.
1715

1816
{% tabs %}
1917
{% highlight js tabtitle="app.jsx" %}

Document-Processing/Excel/Spreadsheet/React/how-to/find-replace-in-range.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,9 @@ documentation: ug
99

1010
# Find and replace the text within the selected range of cells
1111

12-
In the Syncfusion Spreadsheet, you can limit the Replace All action so that it updates only the cells inside the users selected range. When the replace operation begins, the selection is read and converted into individual cell addresses. During the beforeReplaceAll action, the list of cells targeted by Replace All is filtered so only the addresses inside the selected ranges are collected by generateCellCollection method.
12+
In Syncfusion Spreadsheet, the "Replace all" action normally searches the entire sheet and does not consider the user's selected range. The sample below shows how you can prevent the Replace all operation to entire sheet, so it updates only the cells inside the selected range.
1313

14-
The following sample shows how the selected range is expanded, compared with address collection, and updated so that Replace All applies only the chosen cells in the active sheet.
14+
The selected range is captured during the [actionBegin](https://ej2.syncfusion.com/documentation/api/spreadsheet/index-default#actionbegin) event. This range is then expanded into individual cell addresses. The cell value is replaced only if it falls within this selected range.
1515

1616
{% tabs %}
1717
{% highlight js tabtitle="app.jsx" %}

Document-Processing/Excel/Spreadsheet/React/how-to/get-filtered-data.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@ documentation: ug
99

1010
# Get filtered row data in React Spreadsheet
1111

12-
Filtering allows you to view specific rows that match your criteria while hiding the rest. You can enable filtering using the [allowFiltering](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#allowfiltering) property and apply filters through the UI or with the [applyFilter](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#applyfilter) method in code. The filtered rows can be identified by iterating through the row collection on the sheet and using the isFiltered property available in each row object. The filtered row includes an `isFiltered` flag that tells whether the row is hidden or visible.
12+
Filtering in the Syncfusion Spreadsheet allows you to display only the rows that match your criteria, hiding all others. You can enable filtering by setting the [allowFiltering](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#allowfiltering) property, and apply filters either through the UI or programmatically using the [applyFilter](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#applyfilter) method. To identify which rows are filtered, iterate through the sheet's row collection and check the `isFiltered` property of each row object. This flag indicates whether a row is currently hidden due to filtering.
1313

1414
The following example shows how to get the filtered rows from the Spreadsheet:
1515

Document-Processing/code-snippet/spreadsheet/react/add-icon-in-cell-cs1/app/app.jsx

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import React, { useRef } from 'react';
2+
import { createRoot } from 'react-dom/client';
23
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
34

45
function App() {

Document-Processing/code-snippet/spreadsheet/react/add-icon-in-cell-cs1/app/app.tsx

Lines changed: 5 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,15 @@
11
import React, { useRef } from 'react';
2+
import { createRoot } from 'react-dom/client';
23
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
34

45
function App(): React.ReactElement {
56
const spreadsheetRef = useRef<SpreadsheetComponent | null>(null);
67

78
// To create plus icon wrapper.
89
const createPlusIconWrapper = (): HTMLElement => {
9-
const wrapperDiv = document.createElement('div');
10+
const wrapperDiv: HTMLDivElement = document.createElement('div');
1011
wrapperDiv.className = 'e-custom-wrapper';
11-
const iconSpan = document.createElement('span');
12+
const iconSpan: HTMLSpanElement = document.createElement('span');
1213
iconSpan.className = 'e-icons e-plus e-custom-icon';
1314
wrapperDiv.appendChild(iconSpan);
1415
return wrapperDiv;
@@ -33,7 +34,7 @@ function App(): React.ReactElement {
3334
click: () => {
3435
if (!spreadsheetRef.current) return;
3536
// Add the plus icon template to the selected cell
36-
const sheet = spreadsheetRef.current.getActiveSheet();
37+
const sheet: any = spreadsheetRef.current.getActiveSheet();
3738
spreadsheetRef.current.updateCell({ template: 'plus-icon' } as any, (sheet as any).activeCell);
3839
spreadsheetRef.current.resize();
3940
},
@@ -47,7 +48,7 @@ function App(): React.ReactElement {
4748
const handleBeforeCellRender = (args: any) => {
4849
if (args.cell && args.cell.template === 'plus-icon') {
4950
// Pass the rowIndex to the wrapper to make the click handler reliable.
50-
const wrapperDiv = createPlusIconWrapper();
51+
const wrapperDiv: HTMLElement = createPlusIconWrapper();
5152
args.element.insertBefore(wrapperDiv, args.element.firstChild);
5253
}
5354
};

Document-Processing/code-snippet/spreadsheet/react/dynamic-cell-template-cs1/app/app.jsx

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -54,6 +54,9 @@ function App() {
5454
placeholder: 'Select a value',
5555
dataSource: legendOptions,
5656
cssClass: 'e-dropdown-list',
57+
change: (event)=>{
58+
spreadsheetRef.current?.updateCell({value: event.value.toString()}, ( spreadsheet?.getActiveSheet()).activeCell);
59+
}
5760
}, inputEle);
5861
};
5962

Document-Processing/code-snippet/spreadsheet/react/dynamic-cell-template-cs1/app/app.tsx

Lines changed: 12 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
1-
import { useRef } from 'react';
1+
import React, { useRef } from 'react';
2+
import { createRoot } from 'react-dom/client';
23
import { SpreadsheetComponent, getCellIndexes, getCell, setCell } from '@syncfusion/ej2-react-spreadsheet';
34
import { DropDownList } from '@syncfusion/ej2-dropdowns';
45

5-
function App() {
6+
function App(): React.ReactElement {
67
let spreadsheet: SpreadsheetComponent | null = null;
78
const spreadsheetRef = useRef<SpreadsheetComponent | null>(null);
89

@@ -16,18 +17,18 @@ function App() {
1617
spreadsheet.addRibbonTabs([{ header: { text: 'Template' }, content: [{
1718
text: 'DropDown List', click: () => {
1819
if (!spreadsheet) return;
19-
const sheet = spreadsheet.getActiveSheet();
20-
const [rowIdx, colIdx] = getCellIndexes((sheet as any).activeCell);
21-
const cellModel = getCell(rowIdx, colIdx, sheet as any);
22-
const cellEle = spreadsheet.getCell(rowIdx, colIdx);
20+
const sheet: any = spreadsheet.getActiveSheet();
21+
const [rowIdx, colIdx]: number[] = getCellIndexes((sheet as any).activeCell);
22+
const cellModel: any = getCell(rowIdx, colIdx, sheet as any);
23+
const cellEle: HTMLElement = spreadsheet.getCell(rowIdx, colIdx) as HTMLElement;
2324
if (cellModel && (cellModel as any).template === 'dropdown-list') return;
2425
addDropDownlist(cellEle as any, dropDownOptions);
2526
}
2627
}] }]);
2728

2829
spreadsheet.setRowsHeight(35, ['1:100']);
2930
// Rendering dropdown list for a specific range initially.
30-
const activeSheet = spreadsheet.getActiveSheet();
31+
const activeSheet: any = spreadsheet.getActiveSheet();
3132
for (let colIdx = 0; colIdx <= 3; colIdx++) {
3233
setCell(0, colIdx, activeSheet as any, { template: 'dropdown-list' } as any, true);
3334
}
@@ -47,12 +48,15 @@ function App() {
4748
// To render the dropdown list.
4849
const addDropDownlist = (element: HTMLElement, legendOptions: number[]): void => {
4950
element.innerHTML = '';
50-
const inputEle = document.createElement('input');
51+
const inputEle: HTMLInputElement = document.createElement('input');
5152
element.appendChild(inputEle);
5253
new DropDownList({
5354
placeholder: 'Select a value',
5455
dataSource: legendOptions,
5556
cssClass: 'e-dropdown-list',
57+
change: (event: any)=>{
58+
spreadsheetRef.current?.updateCell({value: event.value.toString()}, ( spreadsheet?.getActiveSheet() as any).activeCell);
59+
}
5660
}, inputEle);
5761
};
5862

Document-Processing/code-snippet/spreadsheet/react/find-and-replace-cs1/app/app.jsx

Lines changed: 30 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,46 @@
11
import * as React from 'react';
2-
import './App.css';
2+
import { createRoot } from 'react-dom/client';
33
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
44
import { getDefaultData } from './data';
55

66
function App() {
77
const spreadsheetRef = React.useRef(null);
88

99
const actionBegin = (args) => {
10-
const action = args?.action;
11-
const eventArgs = args?.eventArgs;
10+
const action = args.action;
11+
const eventArgs = args.args.eventArgs;
1212

1313
// Check the action is beforeReplaceAll.
1414
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 = spreadsheet.getActiveSheet()?.selectedRange;
22-
if (!selectedRange) return;
23-
24-
// Convert the selected range into cell collection.
25-
const selectedRangeCollection = generateCellCollection(selectedRange, spreadsheet);
26-
const replaceAllCollection = eventArgs.addressCollection;
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 = [];
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 = spreadsheet.getActiveSheet()?.selectedRange;
20+
if (!selectedRange) return;
21+
22+
// Convert the selected range into cell collection.
23+
const selectedRangeCollection = generateCellCollection(selectedRange, spreadsheet);
24+
const replaceAllCollection = eventArgs.addressCollection;
25+
if (!Array.isArray(replaceAllCollection)) return;
26+
27+
// Create a Set from selectedRangeCollection for efficient lookup.
28+
const selectedSet = new Set(selectedRangeCollection);
29+
const updatedCollection = [];
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);
4138
}
39+
}
4240

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;
4744
}
4845
}
4946
};

Document-Processing/code-snippet/spreadsheet/react/find-and-replace-cs1/app/app.tsx

Lines changed: 32 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -1,49 +1,46 @@
11
import * as React from 'react';
2-
import './App.css';
2+
import { createRoot } from 'react-dom/client';
33
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
44
import { getDefaultData } from './data';
55

6-
function App() {
7-
const spreadsheetRef = React.useRef<SpreadsheetComponent>(null);
6+
function App(): React.ReactElement {
7+
const spreadsheetRef = React.useRef<SpreadsheetComponent | null>(null);
88

99
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;
1212

1313
// Check the action is beforeReplaceAll.
1414
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);
4138
}
39+
}
4240

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;
4744
}
4845
}
4946
};

0 commit comments

Comments
 (0)