Painting

You can repaint the worksheet and use suspendPaint and resumePaint function to speed up the rendering performance.

After the user changes the sheet, the Spread component needs to deal with these changes and paint a new sheet. You can use the repaint method to repaint the sheet. Most of the time, after you change the sheet, the component will auto refresh to respond to the changes. If you make a lot of changes at one time, but don't want the sheet to repaint many times, then you can use the suspendPaint method to stop the automatic repaint until the changes are complete. Then call the resumePaint method to redraw the sheet, as shown in the following example:
import * as React from 'react'; import { createRoot } from 'react-dom/client'; import './styles.css'; import { AppFunc } from './app-func'; import { App } from './app-class'; // 1. Functional Component sample createRoot(document.getElementById('app')).render(<AppFunc />); // 2. Class Component sample // createRoot(document.getElementById('app')).render(<App />);
import * as React from 'react'; import Panel from './panel'; import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react'; let spreadFinal; export function AppFunc() { return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => initSpread(spread)}> <Worksheet> </Worksheet> </SpreadSheets> </div> <Panel suspendPaint={() => { suspendPaint() }} setValue={() => { setValue() }} resumePaint={() => { resumePaint() }} ></Panel> </div> ) } function setValue() { var sheet = spreadFinal.getActiveSheet(); var cellRange = sheet.getSelections()[0]; var salesData = [ ["Salesperson", "Region", "Sales Amount", "Commission %", "Commission Amount"], ["Joe", "North", 260, '10%', 26], ["Robert", "South", 660, '15%', 99], ["Michelle", "East", 940, '15%', 141], ["Erich", "West", 410, '12%', 49.2], ["Dafna", "North", 800, '15%', 120], ["Rob", "South", 900, '15%', 135] ]; if (cellRange) { for (var row = cellRange.row, rowCount = cellRange.row + cellRange.rowCount; row < rowCount; row++) { for (var col = cellRange.col, colCount = cellRange.col + cellRange.colCount; col < colCount; col++) { sheet.setArray(row, col, salesData); sheet.getCell(row, col).foreColor("lightGreen"); sheet.getCell(row, ++col).foreColor("lightGreen"); sheet.getCell(row, ++col).foreColor("lightGreen"); sheet.getCell(row, ++col).foreColor("lightGreen"); sheet.getCell(row, ++col).foreColor("lightGreen"); } } } } function suspendPaint() { spreadFinal.suspendPaint(); } function resumePaint() { spreadFinal.resumePaint(); } function initSpread(spread) { spreadFinal = spread; }
import * as React from 'react'; import Panel from './panel'; import { SpreadSheets, Worksheet } from '@mescius/spread-sheets-react'; let spreadFinal; export class App extends React.Component { render() { return ( <div class="sample-tutorial"> <div class="sample-spreadsheets"> <SpreadSheets workbookInitialized={spread => initSpread(spread)}> <Worksheet> </Worksheet> </SpreadSheets> </div> <Panel suspendPaint={() => { suspendPaint() }} setValue={() => { setValue() }} resumePaint={() => { resumePaint() }} ></Panel> </div> ); } } function setValue() { var sheet = spreadFinal.getActiveSheet(); var cellRange = sheet.getSelections()[0]; var salesData = [ ["Salesperson", "Region", "Sales Amount", "Commission %", "Commission Amount"], ["Joe", "North", 260, '10%', 26], ["Robert", "South", 660, '15%', 99], ["Michelle", "East", 940, '15%', 141], ["Erich", "West", 410, '12%', 49.2], ["Dafna", "North", 800, '15%', 120], ["Rob", "South", 900, '15%', 135] ]; if (cellRange) { for (var row = cellRange.row, rowCount = cellRange.row + cellRange.rowCount; row < rowCount; row++) { for (var col = cellRange.col, colCount = cellRange.col + cellRange.colCount; col < colCount; col++) { sheet.setArray(row, col, salesData); sheet.getCell(row, col).foreColor("lightGreen"); sheet.getCell(row, ++col).foreColor("lightGreen"); sheet.getCell(row, ++col).foreColor("lightGreen"); sheet.getCell(row, ++col).foreColor("lightGreen"); sheet.getCell(row, ++col).foreColor("lightGreen"); } } } } function suspendPaint() { spreadFinal.suspendPaint(); } function resumePaint() { spreadFinal.resumePaint(); } function initSpread(spread) { spreadFinal = spread; }
import * as React from 'react'; export default function Panel(props) { const { suspendPaint, setValue, resumePaint } = props; return ( <div class="options-container"> <div class="option-row"> <input type="button" id="suspendPaint" value="Suspend Paint" onClick={suspendPaint} /> <label>1. Suspend the paint of Workbook</label> </div> <div class="option-row"> <input type="button" id="setValue" value="Set Value Array" onClick={setValue} /> <label>2. Set a range set of values on the sheet</label> </div> <div class="option-row"> <input type="button" id="resumePaint" value="Resume Paint" onClick={resumePaint} /> <label>3. Resume the paint of Workbook</label> </div> </div> ); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/en/react/node_modules/@mescius/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <!-- SystemJS --> <script src="$DEMOROOT$/en/react/node_modules/systemjs/dist/system.src.js"></script> <script src="systemjs.config.js"></script> <script> System.import('$DEMOROOT$/en/lib/react/license.js').then(function () { System.import('./src/app'); }); </script> </head> <body> <div id="app" style="height: 100%;"></div> </body> </html>
.sample-tutorial { position: relative; height: 100%; overflow: hidden; } .sample-spreadsheets { width: calc(100% - 280px); height: 100%; overflow: hidden; float: left; } .options-container { float: right; width: 280px; padding: 12px; height: 100%; box-sizing: border-box; background: #fbfbfb; overflow: auto; } .option-row { font-size: 14px; padding: 5px; margin-top: 10px; } label { display: block; margin-bottom: 6px; } input { padding: 4px 6px; } .labelStyle { color:rgb(226,107,29); display:inline-block; font-family:Arial, Helvetica, sans-serif; font-size: 18px; font-weight: normal; height:30px; line-height: 30px } input[type=button] { margin-top: 6px; display: block; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }
(function (global) { System.config({ transpiler: 'plugin-babel', babelOptions: { es2015: true, react: true }, meta: { '*.css': { loader: 'css' } }, paths: { // paths serve as alias 'npm:': 'node_modules/' }, // map tells the System loader where to look for things map: { '@mescius/spread-sheets': 'npm:@mescius/spread-sheets/index.js', '@mescius/spread-sheets-react': 'npm:@mescius/spread-sheets-react/index.js', '@grapecity/jsob-test-dependency-package/react-components': 'npm:@grapecity/jsob-test-dependency-package/react-components/index.js', 'react': 'npm:react/cjs/react.production.js', 'react-dom': 'npm:react-dom/cjs/react-dom.production.js', 'react-dom/client': 'npm:react-dom/cjs/react-dom-client.production.js', 'scheduler': 'npm:scheduler/cjs/scheduler.production.js', 'css': 'npm:systemjs-plugin-css/css.js', 'plugin-babel': 'npm:systemjs-plugin-babel/plugin-babel.js', 'systemjs-babel-build':'npm:systemjs-plugin-babel/systemjs-babel-browser.js' }, // packages tells the System loader how to load when no filename and/or no extension packages: { src: { defaultExtension: 'jsx' }, "node_modules": { defaultExtension: 'js' }, } }); })(this);