描画

SpreadJSでは、ワークシートを再描画し、レンダリングパフォーマンスを向上させることができます。

<p>ユーザーがシートに変更を加えた後は、Spreadコンポーネントはこの変更を処理し、新たなシートを描画する必要があります。</p> <p><strong>repaint</strong>メソッドを使用しても、シートを再描画できます。</p> <pre><code class="hljs js language-js"> <span class="hljs-keyword">var</span> spread = GC.Spread.Sheets.findControl(<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'ss'</span>)); <span class="hljs-keyword">var</span> sheet = spread.getActiveSheet(); sheet.repaint(); </code></pre> <p>通常、シートに変更が加えられるとコンポーネントは自動的に更新し、変更を反映させます。一度に大量の変更を加える場合、シートが何度も再描画されないようにするには、<strong>suspendPaint</strong>メソッドを使用すると、必要な変更がすべて完了するまで自動再描画が停止されます。変更が完了したら、<strong>resumePaint</strong>メソッドを呼び出してシートを再描画します。次に、この例を示します。</p> <pre><code class="hljs js language-js"> <span class="hljs-keyword">var</span> spread = GC.Spread.Sheets.findControl(<span class="hljs-built_in">document</span>.getElementById(<span class="hljs-string">'ss'</span>)); <span class="hljs-keyword">var</span> sheet = spread.getActiveSheet(); sheet.suspendPaint(); sheet.setValue(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>, <span class="hljs-string">'Click me and input a char by keyboard!'</span>); sheet.addSpan(<span class="hljs-number">2</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">5</span>); sheet.setValue(<span class="hljs-number">4</span>, <span class="hljs-number">2</span>, <span class="hljs-string">'Double click the black empty cell!'</span>); sheet.addSpan(<span class="hljs-number">4</span>, <span class="hljs-number">2</span>, <span class="hljs-number">1</span>, <span class="hljs-number">5</span>); <span class="hljs-comment">// 処理を追加します。</span> sheet.resumePaint(); </code></pre>
window.onload = function() { var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"), { sheetCount: 1 }); var spreadNS = GC.Spread.Sheets; document.getElementById("setValue").addEventListener('click',function() { var sheet = spread.getActiveSheet(); var cellRange = sheet.getSelections()[0]; 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++) { var salesData = [ ["SalesPers", "Region", "SaleAmt", "ComPct", "ComAmt"], ["Joe", "North", 260, 0.1, 26], ["Robert", "South", 660, 0.15, 99], ["Michelle", "East", 940, 0.15, 141], ["Erich", "West", 410, 0.12, 49.2], ["Dafna", "North", 800, 0.15, 120], ["Rob", "South", 900, 0.15, 135] ]; 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 getActualRange(range, maxRowCount, maxColCount) { var row = range.row < 0 ? 0 : range.row; var col = range.col < 0 ? 0 : range.col; var rowCount = range.rowCount < 0 ? maxRowCount : range.rowCount; var colCount = range.colCount < 0 ? maxColCount : range.colCount; return new spreadNS.Range(row, col, rowCount, colCount); } document.getElementById("suspendPaint").addEventListener('click',function() { spread.suspendPaint(); }); document.getElementById("resumePaint").addEventListener('click',function() { spread.resumePaint(); }); };
<!doctype html> <html style="height:100%;font-size:14px;"> <head> <meta name="spreadjs culture" content="ja-jp" /> <meta charset="utf-8" /> <meta name="viewport" content="width=device-width, initial-scale=1.0" /> <link rel="stylesheet" type="text/css" href="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/styles/gc.spread.sheets.excel2013white.css"> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets/dist/gc.spread.sheets.all.min.js" type="text/javascript"></script> <script src="$DEMOROOT$/ja/purejs/node_modules/@grapecity/spread-sheets-resources-ja/dist/gc.spread.sheets.resources.ja.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"> <input type="button" id="suspendPaint" value="描画を一時停止" /> <label>ワークブックの描画を一時停止します。</label> </div> <div class="option-row"> <input type="button" id="setValue" value="値配列を設定" /> <label>シートに一連の値を設定します。</label> </div> <div class="option-row"> <input type="button" id="resumePaint" value="描画を再開" /> <label>ワークブックの描画を再開します。</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: 6px; display: block; } body { position: absolute; top: 0; bottom: 0; left: 0; right: 0; }