Spread绘制

通过使用 suspendPaint/resumePaint 方法你可以提升渲染性能。 Suspend PaintResume Paint用于在耗时的更新期间暂停和恢复绘制以提高渲染性能。

在你通过 API 或行为改变 Spread 之后, 控件需要处理这些改变, 然后进行重绘。 大多数时候, 在你改变 Spread 之后, 控件会自动刷新以达到重绘和更新状态的目的。 可是, 如果你一次做出大量的改变, 并且不希望每次改变都去重新绘制 Spread , 那么你可以调用 suspendPaint 暂停重绘, 完成改变之后,你可以调用resumePaint 重新激活Spread重绘,例如: 如果你的代码逻辑对控件进行修改,但控件未进行自刷新,那么你可以调用repaint方法强制刷新。
window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(_getElementById('ss'), { sheetCount: 1 }); initSpread(spread); }; function initSpread(spread) { spread.suspendPaint(); spread.getSheet(0); var sheet = spread.getActiveSheet(); spread.resumePaint(); _getElementById('btnAddSheet').addEventListener('click', function() { spread.addSheet(0); }); _getElementById('suspendPaint').addEventListener('click', function() { spread.suspendPaint(); }); _getElementById('resumePaint').addEventListener('click', function() { spread.resumePaint(); }); } function _getElementById(id){ return document.getElementById(id); }
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="zh-cn" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/data/data.js" type="text/javascript"></script> <script src="$DEMOROOT$/zh/purejs/node_modules/@grapecity-software/spread-sheets-resources-zh/dist/gc.spread.sheets.resources.zh.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/spread/source/js/license.js" type="text/javascript"></script> <script src="app.js" type="text/javascript"></script> <link rel="stylesheet" type="text/css" href="styles.css"> </head> <body> <div class="sample-tutorial"> <div id="ss" class="sample-spreadsheets"></div> <div class="options-container"> <div class="option-row"> <label>Click buttons to suspend and resume painting the Spread component, and see how actions are affected by that state.</label> </div> 1. Click 'Suspend Paint' <input type="button" id="suspendPaint" value="Suspend Paint" /> <br /> 2. Add various sheets <input type="button" id="btnAddSheet" value="Add Sheet" /> <br /> 3. Click 'Resume Paint' <input type="button" id="resumePaint" value="Resume Paint" /> <div class="option-row"> <label>The rendering performance improves when using suspendPaint/ResumePaint functionality. </label> </div> </div> </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; } input[type=button] { margin-top: 16px; display: block; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }