Skip to content

Commit 7b407b1

Browse files
committed
1012637: updated How to session for react spreadsheet in ug documentation
1 parent fb30304 commit 7b407b1

14 files changed

Lines changed: 62 additions & 141 deletions

File tree

Document-Processing-toc.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5314,7 +5314,7 @@
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/dynamic-cell-dropdown">Add dynamic cell templates in the spreadsheet</a></li>
5317+
<li><a href="/document-processing/excel/spreadsheet/react/how-to/dynamic-cell-template">Add dynamic cell templates in the spreadsheet</a></li>
53185318
<li><a href="/document-processing/excel/spreadsheet/react/how-to/dynamic-cell-icon">Add an icon to the cell in the spreadsheet</a></li>
53195319
<li><a href="/document-processing/excel/spreadsheet/react/how-to/filter-row">Get the filtered row data in a spreadsheet</a></li>
53205320
</ul>

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

Lines changed: 0 additions & 43 deletions
This file was deleted.

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

Lines changed: 3 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -7,27 +7,11 @@ platform: document-processing
77
documentation: ug
88
---
99

10-
## Add Custom Icons to Cells in React Spreadsheet
10+
# Add Custom Icons to Cells in React Spreadsheet
1111

12-
This guide demonstrates how to add a custom icons in cells in the Syncfusion React Spreadsheet component.
12+
Icons can be initialized directly in specific cells when the sheet loads. A custom Ribbon tab can also be added so you can insert the icon into the selected cell. You can attach your own event for actions to that icon such as showing child rows, inserting new rows, loading extra data, or anything else you need.
1313

14-
A template name is assigned to the cell, and this tells the Spreadsheet to render a custom DOM element instead of normal text. The icon is created using a wrapper function, and during beforeCellRender the wrapper is inserted into the cell when the template name matches.
15-
16-
You can mark a cell with this template using updateCell, or you can apply templates automatically in the created event if you want certain cells to show icons when the sheet loads.
17-
18-
You can also add a custom button in the Ribbon so users can insert the icon into the active cell at any time. When the user clicks the button, the template is applied to the selected cell immediately.
19-
20-
The icon inside the cell acts like a normal clickable element. You can attach your own event for actions such as showing child rows, inserting new rows, loading extra data, or anything else you need. The logic stays simple because the cell only stores the template name, and the actual icon is inserted during rendering.
21-
22-
### Icon insertion logic:
23-
24-
Add icons into cells by marking a cell with a template (for example, `updateCell({ template: 'plus-icon' }, address)`) or by initializing templates programmatically in `created`.
25-
The sample creates a DOM wrapper via `createPlusIconWrapper()` and inserts it in `beforeCellRender` when `cell.template === 'plus-icon'`.
26-
27-
You can add the template to the active cell via a custom ribbon button (the sample uses `addRibbonTabs` → "Add Icon"), or apply templates to ranges on initialization.
28-
When inserted, the icon is a clickable DOM element you control; handle clicks to perform actions like expanding rows, loading data, or inserting rows.
29-
30-
This approach keeps logic simple: mark cells with a template, render a small DOM icon in `beforeCellRender`, and respond to click events to implement custom behavior.
14+
Add icons using [updateCell](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#updatecell) method. A wrapper element is generated and inserted in `beforeCellRender` when the cell contains the icon template.
3115

3216
The following code example shows how to add custom icons to cells for grouping functionality:
3317

Document-Processing/Excel/Spreadsheet/React/how-to/filter-row.md

Lines changed: 2 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -7,17 +7,9 @@ platform: document-processing
77
documentation: ug
88
---
99

10-
## Get filtered row data in React Spreadsheet
10+
# Get filtered row data in React Spreadsheet
1111

12-
This guide explains how to get the filtered row data in the Syncfusion React Spreadsheet component.
13-
14-
When filtering is used, some rows stay visible and the others are hidden. To get only the filtered rows, you can loop through the row collection in the active sheet. Each row has an `isFiltered` property that tells whether the row is hidden by the filter. Rows that are not filtered can then be processed or used for your own logic.
15-
16-
You can apply filters through the UI or use the `applyFilter` method in code. After filtering, you can get the filtered results in a simple way by checking each row and picking the ones that are currently shown to the user.
17-
18-
### Filtered row extraction logic:
19-
20-
Filtering can be enabled with the `allowFiltering` property. After a filter is applied, the row objects in the active sheet include an `isFiltered` flag. By checking this flag, you can identify which rows are included in the filter results. This helps when you need to work only with the visible rows, such as exporting, validating, or processing filtered data.
12+
You can read only the visible rows after filtering by checking the `isFiltered` property on each row. Filters can be applied through the UI or by using `applyFilter` in code, and the same row collection can then be used to extract the filtered data. This helps when you need to work only with the displayed rows for tasks such as exporting, validating, or processing filtered content.
2113

2214
The following example shows how to get the filtered rows from the Spreadsheet:
2315

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

Lines changed: 4 additions & 12 deletions
Original file line numberDiff line numberDiff line change
@@ -7,21 +7,13 @@ platform: document-processing
77
documentation: ug
88
---
99

10-
## Find and replace the text within the selected range of cells
10+
# Find and replace the text within the selected range of cells
1111

12-
It explains how you can limit the Find and Replace action so it works only inside the cells that the user has selected.
12+
You can limit Replace All so it only updates the cells inside the selected range. When the action runs, the selected range is expanded into individual cell addresses and compared with the cells returned by Replace All.
1313

14-
When the user clicks Replace All, the Spreadsheet normally searches the whole sheet. To avoid that, the action is checked before it runs. During this check, the selected range in the active sheet is read and expanded into individual cell addresses.
14+
Intercepts the beforeReplaceAll action via [actionBegin](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#actionbegin), reads selectedRange, expands it to cell addresses, and filters addressCollection to match only the selection.
1515

16-
The list of cells that the Replace All action plans to update is then filtered, keeping only the addresses that fall inside the selected range. With this, Replace All updates only the cells the user has selected and nothing outside that area.
17-
18-
Limit the Replace All operation to the user’s current selection by intercepting the Replace action (`actionBegin`) and filtering `eventArgs.addressCollection` using `getActiveSheet().selectedRange`. This ensures only addresses inside the selected range are updated.
19-
20-
This guide explains how to limit the “Replace All” operation so that replacements occur only within the currently selected range of cells in the Syncfusion React Spreadsheet component.
21-
22-
Intercepts the beforeReplaceAll action via [actionBegin](https://ej2.syncfusion.com/react/documentation/api/spreadsheet/index-default#actionbegin), reads getActiveSheet().selectedRange, expands it to cell addresses, and filters eventArgs.addressCollection to match only the selection.
23-
24-
The following code example shows how to find and replace the text within the selected range of cells
16+
The following code example shows how to find and replace the text within the selected range of cells:
2517

2618
{% tabs %}
2719
{% highlight js tabtitle="app.jsx" %}

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ function App() {
1717
// Triggers after the component is created
1818
const handleCreated = () => {
1919
if (!spreadsheetRef.current) return;
20-
// Add a header Ribbon tab with a button to initialize everything on click.
20+
// Initialize icons in the cells when the spreadsheet loads.
21+
spreadsheetRef.current.updateCell({ template: 'plus-icon' }, 'A1');
22+
spreadsheetRef.current.updateCell({ template: 'plus-icon' }, 'B1');
23+
spreadsheetRef.current.updateCell({ template: 'plus-icon' }, 'C1');
24+
spreadsheetRef.current.resize();
25+
// This is to Add a header Ribbon tab with a button to initialize everything on click.
2126
spreadsheetRef.current.addRibbonTabs([
2227
{
2328
header: { text: 'Template' },
@@ -53,8 +58,6 @@ function App() {
5358
ref={spreadsheetRef}
5459
created={handleCreated}
5560
beforeCellRender={handleBeforeCellRender}
56-
openUrl="https://services.syncfusion.com/js/production/api/spreadsheet/open"
57-
saveUrl="https://services.syncfusion.com/js/production/api/spreadsheet/save"
5861
/>
5962
</div>
6063
);

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

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -17,7 +17,12 @@ function App(): React.ReactElement {
1717
// Triggers after the component is created
1818
const handleCreated = (): void => {
1919
if (!spreadsheetRef.current) return;
20-
// Add a header Ribbon tab with a button to initialize everything on click.
20+
// Initialize icons in the cells when the spreadsheet loads.
21+
spreadsheetRef.current.updateCell({ template: 'plus-icon' } as any, 'A1');
22+
spreadsheetRef.current.updateCell({ template: 'plus-icon' } as any, 'B1');
23+
spreadsheetRef.current.updateCell({ template: 'plus-icon' } as any, 'C1');
24+
spreadsheetRef.current.resize();
25+
// This is to Add a header Ribbon tab with a button to initialize everything on click.
2126
spreadsheetRef.current.addRibbonTabs([
2227
{
2328
header: { text: 'Template' },
@@ -53,8 +58,6 @@ function App(): React.ReactElement {
5358
ref={spreadsheetRef}
5459
created={handleCreated}
5560
beforeCellRender={handleBeforeCellRender}
56-
openUrl="https://services.syncfusion.com/js/production/api/spreadsheet/open"
57-
saveUrl="https://services.syncfusion.com/js/production/api/spreadsheet/save"
5861
/>
5962
</div>
6063
);

Document-Processing/code-snippet/spreadsheet/react/add-icon-in-cell-cs1/index.html

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@
77
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
88
<meta name="description" content="Essential JS 2 for React Components" />
99
<meta name="author" content="Syncfusion" />
10-
<link href="https://cdn.syncfusion.com/ej2/23.1.36/material.css" rel="stylesheet" type="text/css" />
10+
<link href="https://cdn.syncfusion.com/ej2/23.1.36/tailwind3.css" rel="stylesheet" type="text/css" />
1111
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
1212
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
1313
<script src="systemjs.config.js"></script>

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

Lines changed: 18 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
1-
import { useRef } from 'react';
1+
import React, { useRef } from 'react';
22
import { createRoot } from 'react-dom/client';
3-
import { SpreadsheetComponent, setCell } from '@syncfusion/ej2-react-spreadsheet';
3+
import { SpreadsheetComponent, getCellIndexes, getCell, setCell } from '@syncfusion/ej2-react-spreadsheet';
44
import { DropDownList } from '@syncfusion/ej2-dropdowns';
55

66
function App() {
@@ -12,6 +12,20 @@ function App() {
1212
const onCreated = () => {
1313
spreadsheet = spreadsheetRef.current;
1414
if (!spreadsheet) return;
15+
16+
// Custom template tab to add dropdown to cell.
17+
spreadsheet.addRibbonTabs([{ header: { text: 'Template' }, content: [{
18+
text: 'DropDown List', click: () => {
19+
if (!spreadsheet) return;
20+
const sheet = spreadsheet.getActiveSheet();
21+
const [rowIdx, colIdx] = getCellIndexes(sheet.activeCell);
22+
const cellModel = getCell(rowIdx, colIdx, sheet);
23+
const cellEle = spreadsheet.getCell(rowIdx, colIdx);
24+
if (cellModel && cellModel.template === 'dropdown-list') return;
25+
addDropDownlist(cellEle, dropDownOptions);
26+
}
27+
}] }]);
28+
1529
spreadsheet.setRowsHeight(35, ['1:100']);
1630
// Rendering dropdown list for a specific range initially.
1731
const activeSheet = spreadsheet.getActiveSheet();
@@ -21,44 +35,25 @@ function App() {
2135
spreadsheet.resize();
2236
};
2337

24-
// If you want to handle the dropdown via a custom ribbon button, you can
25-
// create a small handler like this:
26-
// const handleCreated = () => {
27-
// const spreadsheet = spreadsheetRef.current;
28-
// spreadsheet.addRibbonTabs([{ header: { text: 'Template' }, content: [{
29-
// text: 'DropDown List', click: () => {
30-
// const sheet = spreadsheet.getActiveSheet();
31-
// const [rowIdx, colIdx] = getCellIndexes(sheet.activeCell);
32-
// const cellModel = getCell(rowIdx, colIdx, sheet);
33-
// const cellEle = spreadsheet.getCell(rowIdx, colIdx);
34-
// if (cellModel && cellModel.template === 'dropdown-list') return;
35-
// addDropDownlist(cellModel, cellEle, dropDownOptions);
36-
// spreadsheet.updateCell({ template: 'dropdown-list' }, sheet.activeCell);
37-
// }
38-
// }] }]);
39-
// };
40-
4138
// Triggers before the cell is appended to the DOM.
4239
const beforeCellRender = (args) => {
4340
if (args.rowIndex !== undefined && args.colIndex !== undefined) {
4441
// To render dropdown if template property 'dropdown-list' is set.
4542
if (args.cell && args.cell.template === 'dropdown-list') {
46-
addDropDownlist(args.cell, args.element, dropDownOptions);
43+
addDropDownlist(args.element, dropDownOptions);
4744
}
4845
}
4946
};
5047

5148
// To render the dropdown list.
52-
const addDropDownlist = (cell, element, legendOptions) => {
49+
const addDropDownlist = (element, legendOptions) => {
5350
element.innerHTML = '';
5451
const inputEle = document.createElement('input');
5552
element.appendChild(inputEle);
5653
new DropDownList({
5754
placeholder: 'Select a value',
5855
dataSource: legendOptions,
5956
cssClass: 'e-dropdown-list',
60-
// Preserve existing value if present
61-
value: cell && cell.value ? cell.value : null,
6257
}, inputEle);
6358
};
6459

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

Lines changed: 17 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import { useRef } from 'react';
2-
import { SpreadsheetComponent, setCell } from '@syncfusion/ej2-react-spreadsheet';
2+
import { SpreadsheetComponent, getCellIndexes, getCell, setCell } from '@syncfusion/ej2-react-spreadsheet';
33
import { DropDownList } from '@syncfusion/ej2-dropdowns';
44

55
function App() {
@@ -11,6 +11,20 @@ function App() {
1111
const onCreated = (): void => {
1212
spreadsheet = spreadsheetRef.current;
1313
if (!spreadsheet) return;
14+
15+
// Custom template tab to add dropdown to cell.
16+
spreadsheet.addRibbonTabs([{ header: { text: 'Template' }, content: [{
17+
text: 'DropDown List', click: () => {
18+
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);
23+
if (cellModel && (cellModel as any).template === 'dropdown-list') return;
24+
addDropDownlist(cellEle as any, dropDownOptions);
25+
}
26+
}] }]);
27+
1428
spreadsheet.setRowsHeight(35, ['1:100']);
1529
// Rendering dropdown list for a specific range initially.
1630
const activeSheet = spreadsheet.getActiveSheet();
@@ -20,44 +34,25 @@ function App() {
2034
spreadsheet.resize();
2135
};
2236

23-
// If you want to handle the dropdown via a custom ribbon button, you can
24-
// create a small handler like this:
25-
// const handleCreated = (): void => {
26-
// const spreadsheet = spreadsheetRef.current!;
27-
// spreadsheet.addRibbonTabs([{ header: { text: 'Template' }, content: [{
28-
// text: 'DropDown List', click: () => {
29-
// const sheet = spreadsheet.getActiveSheet();
30-
// const [rowIdx, colIdx] = getCellIndexes((sheet as any).activeCell);
31-
// const cellModel = getCell(rowIdx, colIdx, sheet as any);
32-
// const cellEle = spreadsheet.getCell(rowIdx, colIdx);
33-
// if (cellModel && (cellModel as any).template === 'dropdown-list') return;
34-
// addDropDownlist(cellModel, cellEle as any, dropDownOptions);
35-
// spreadsheet.updateCell({ template: 'dropdown-list' } as any, (sheet as any).activeCell);
36-
// }
37-
// }] }]);
38-
// };
39-
4037
// Triggers before the cell is appended to the DOM.
4138
const beforeCellRender = (args: any): void => {
4239
if (args.rowIndex !== undefined && args.colIndex !== undefined) {
4340
// To render dropdown if template property 'dropdown-list' is set.
4441
if (args.cell && args.cell.template === 'dropdown-list') {
45-
addDropDownlist(args.cell, args.element as HTMLElement, dropDownOptions);
42+
addDropDownlist(args.element as HTMLElement, dropDownOptions);
4643
}
4744
}
4845
};
4946

5047
// To render the dropdown list.
51-
const addDropDownlist = (cell: any, element: HTMLElement, legendOptions: number[]): void => {
48+
const addDropDownlist = (element: HTMLElement, legendOptions: number[]): void => {
5249
element.innerHTML = '';
5350
const inputEle = document.createElement('input');
5451
element.appendChild(inputEle);
5552
new DropDownList({
5653
placeholder: 'Select a value',
5754
dataSource: legendOptions,
5855
cssClass: 'e-dropdown-list',
59-
// Preserve existing value if present
60-
value: cell && cell.value ? (cell.value as any) : null,
6156
}, inputEle);
6257
};
6358

0 commit comments

Comments
 (0)