Skip to content

Commit d913963

Browse files
committed
1011961: Updated the preview samples code for how to session
1 parent 563a6a5 commit d913963

8 files changed

Lines changed: 263 additions & 35 deletions

File tree

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

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
import React, { useRef } from 'react';
1+
import * as React from 'react';
22
import { createRoot } from 'react-dom/client';
33
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
44

55
function App() {
6-
const spreadsheetRef = useRef(null);
6+
const spreadsheetRef = React.useRef(null);
77

88
// To create plus icon wrapper.
99
const createPlusIconWrapper = () => {
10-
const wrapperDiv = document.createElement('div');
10+
const wrapperDiv = document.createElement("div");
1111
wrapperDiv.className = 'e-custom-wrapper';
12-
const iconSpan = document.createElement('span');
12+
const iconSpan = document.createElement("span");
1313
iconSpan.className = 'e-icons e-plus e-custom-icon';
1414
wrapperDiv.appendChild(iconSpan);
1515
return wrapperDiv;
1616
};
1717

18-
// Triggers after the component is created
1918
const handleCreated = () => {
2019
if (!spreadsheetRef.current) return;
21-
// Initialize icons in the cells when the spreadsheet loads.
2220
spreadsheetRef.current.updateCell({ template: 'plus-icon' }, 'A1');
2321
spreadsheetRef.current.updateCell({ template: 'plus-icon' }, 'B1');
2422
spreadsheetRef.current.updateCell({ template: 'plus-icon' }, 'C1');
2523
spreadsheetRef.current.resize();
26-
// This is to Add a header Ribbon tab with a button to initialize everything on click.
2724
spreadsheetRef.current.addRibbonTabs([
2825
{
2926
header: { text: 'Template' },
@@ -33,7 +30,6 @@ function App() {
3330
tooltipText: 'Initialize',
3431
click: () => {
3532
if (!spreadsheetRef.current) return;
36-
// Add the plus icon template to the selected cell
3733
const sheet = spreadsheetRef.current.getActiveSheet();
3834
spreadsheetRef.current.updateCell({ template: 'plus-icon' }, sheet.activeCell);
3935
spreadsheetRef.current.resize();
@@ -44,10 +40,8 @@ function App() {
4440
]);
4541
};
4642

47-
// Triggers before the cell is appended to DOM
4843
const handleBeforeCellRender = (args) => {
4944
if (args.cell && args.cell.template === 'plus-icon') {
50-
// Pass the rowIndex to the wrapper to make the click handler reliable.
5145
const wrapperDiv = createPlusIconWrapper();
5246
args.element.insertBefore(wrapperDiv, args.element.firstChild);
5347
}

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

Lines changed: 8 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -1,29 +1,26 @@
1-
import React, { useRef } from 'react';
1+
import * as React from 'react';
22
import { createRoot } from 'react-dom/client';
33
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
44

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

88
// To create plus icon wrapper.
99
const createPlusIconWrapper = (): HTMLElement => {
10-
const wrapperDiv: HTMLDivElement = document.createElement('div');
10+
const wrapperDiv: HTMLDivElement = document.createElement("div");
1111
wrapperDiv.className = 'e-custom-wrapper';
12-
const iconSpan: HTMLSpanElement = document.createElement('span');
12+
const iconSpan: HTMLSpanElement = document.createElement("span");
1313
iconSpan.className = 'e-icons e-plus e-custom-icon';
1414
wrapperDiv.appendChild(iconSpan);
1515
return wrapperDiv;
1616
};
1717

18-
// Triggers after the component is created
1918
const handleCreated = (): void => {
2019
if (!spreadsheetRef.current) return;
21-
// Initialize icons in the cells when the spreadsheet loads.
2220
spreadsheetRef.current.updateCell({ template: 'plus-icon' } as any, 'A1');
2321
spreadsheetRef.current.updateCell({ template: 'plus-icon' } as any, 'B1');
2422
spreadsheetRef.current.updateCell({ template: 'plus-icon' } as any, 'C1');
2523
spreadsheetRef.current.resize();
26-
// This is to Add a header Ribbon tab with a button to initialize everything on click.
2724
spreadsheetRef.current.addRibbonTabs([
2825
{
2926
header: { text: 'Template' },
@@ -33,9 +30,11 @@ function App(): React.ReactElement {
3330
tooltipText: 'Initialize',
3431
click: () => {
3532
if (!spreadsheetRef.current) return;
36-
// Add the plus icon template to the selected cell
3733
const sheet: any = spreadsheetRef.current.getActiveSheet();
38-
spreadsheetRef.current.updateCell({ template: 'plus-icon' } as any, (sheet as any).activeCell);
34+
spreadsheetRef.current.updateCell(
35+
{ template: 'plus-icon' } as any,
36+
sheet.activeCell
37+
);
3938
spreadsheetRef.current.resize();
4039
},
4140
},
@@ -44,10 +43,8 @@ function App(): React.ReactElement {
4443
]);
4544
};
4645

47-
// Triggers before the cell is appended to DOM
4846
const handleBeforeCellRender = (args: any) => {
4947
if (args.cell && args.cell.template === 'plus-icon') {
50-
// Pass the rowIndex to the wrapper to make the click handler reliable.
5148
const wrapperDiv: HTMLElement = createPlusIconWrapper();
5249
args.element.insertBefore(wrapperDiv, args.element.firstChild);
5350
}

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

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

66
function App() {
77
let spreadsheet = null;
8-
const spreadsheetRef = useRef(null);
8+
const spreadsheetRef = React.useRef(null);
99

1010
const dropDownOptions = [10, 20, 30, 40, 50, 60];
1111

@@ -48,14 +48,14 @@ function App() {
4848
// To render the dropdown list.
4949
const addDropDownlist = (element, legendOptions) => {
5050
element.innerHTML = '';
51-
const inputEle = document.createElement('input');
51+
const inputEle = document.createElement("input");
5252
element.appendChild(inputEle);
5353
new DropDownList({
5454
placeholder: 'Select a value',
5555
dataSource: legendOptions,
5656
cssClass: 'e-dropdown-list',
5757
change: (event)=>{
58-
spreadsheetRef.current?.updateCell({value: event.value.toString()}, ( spreadsheet?.getActiveSheet()).activeCell);
58+
spreadsheetRef.current.updateCell({value: event.value.toString()}, ( spreadsheet.getActiveSheet()).activeCell);
5959
}
6060
}, inputEle);
6161
};

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

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

66
function App(): React.ReactElement {
7-
let spreadsheet: SpreadsheetComponent | null = null;
8-
const spreadsheetRef = useRef<SpreadsheetComponent | null>(null);
7+
let spreadsheet: SpreadsheetComponent = null;
8+
const spreadsheetRef = React.useRef<SpreadsheetComponent>(null);
99

1010
const dropDownOptions: number[] = [10, 20, 30, 40, 50, 60];
1111

@@ -48,14 +48,14 @@ function App(): React.ReactElement {
4848
// To render the dropdown list.
4949
const addDropDownlist = (element: HTMLElement, legendOptions: number[]): void => {
5050
element.innerHTML = '';
51-
const inputEle: HTMLInputElement = document.createElement('input');
51+
const inputEle: HTMLInputElement = document.createElement("input");
5252
element.appendChild(inputEle);
5353
new DropDownList({
5454
placeholder: 'Select a value',
5555
dataSource: legendOptions,
5656
cssClass: 'e-dropdown-list',
5757
change: (event: any)=>{
58-
spreadsheetRef.current?.updateCell({value: event.value.toString()}, ( spreadsheet?.getActiveSheet() as any).activeCell);
58+
spreadsheetRef.current.updateCell({value: event.value.toString()}, ( spreadsheet.getActiveSheet() as any).activeCell);
5959
}
6060
}, inputEle);
6161
};

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

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,7 +1,7 @@
11
import * as React from 'react';
22
import { createRoot } from 'react-dom/client';
33
import { SpreadsheetComponent } from '@syncfusion/ej2-react-spreadsheet';
4-
import { getDefaultData } from './data';
4+
import { getDefaultData } from './datasource';
55

66
function App() {
77
const spreadsheetRef = React.useRef(null);
@@ -16,7 +16,7 @@ function App() {
1616
if (!spreadsheet) return;
1717

1818
// Get the active sheet's selected range.
19-
const selectedRange = spreadsheet.getActiveSheet()?.selectedRange;
19+
const selectedRange = spreadsheet.getActiveSheet().selectedRange;
2020
if (!selectedRange) return;
2121

2222
// Convert the selected range into cell collection.
@@ -54,7 +54,7 @@ function App() {
5454
endCell = endCell || startCell;
5555

5656
// Get the name of the active sheet.
57-
const activeSheetName = spreadsheet.getActiveSheet()?.name || 'Sheet1';
57+
const activeSheetName = spreadsheet.getActiveSheet().name;
5858

5959
// Extract column and row numbers from start and end cell references.
6060
const [startCol, startRow] = startCell.match(/[A-Z]+|\d+/g) || [];

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

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

66
function App(): React.ReactElement {
77
const spreadsheetRef = React.useRef<SpreadsheetComponent | null>(null);
@@ -16,7 +16,7 @@ function App(): React.ReactElement {
1616
if (!spreadsheet) return;
1717

1818
// Get the active sheet's selected range.
19-
const selectedRange: string | undefined = spreadsheet.getActiveSheet()?.selectedRange;
19+
const selectedRange: string | undefined = spreadsheet.getActiveSheet().selectedRange;
2020
if (!selectedRange) return;
2121

2222
// Convert the selected range into cell collection.

0 commit comments

Comments
 (0)