SpreadJS Documentation
Using suspendPaint and resumePaint
SpreadJS Documentation > Developer's Guide > Best Practices > Using suspendPaint and resumePaint

Each time a change is incorporated in the worksheet, SpreadJS automatically refreshes itself. When a user plans to integrate a lot of changes concurrently, it reduces the performance significantly because SpreadJS is painted repeatedly. Therefore, it is recommended to use the suspendPaint method and the resumePaint method.

The suspendPaint method allows users to stop the repaint process while the modifications are being done. After integrating all the changes, users can invoke the resumePaint method. Both of these methods enhance the overall performance because Spread will now paint only once after all the changes have been done.

Refer to the following code snippet in order to use the suspendPaint method and the resumePaint method.

JavaScript
Copy Code

var spread = new GC.Spread.Sheets.Workbook(document.getElementById('ss'), { sheetCount: 1 });

var sheet = spread.getSheet(0);

spread.suspendPaint();

spread.suspendEvent();

sheet.setRowCount(10000);

sheet.setColumnCount(100);

for (var i = 0; i < 10000; i++)

{

for (var j = 0; j < 100; j++)

{

sheet.setValue(i, j, new Date(), GC.Spread.Sheets.SheetArea.viewport);

sheet.getCell(i, j).formatter("yyyy/mm/dd");

sheet.setColumnWidth(j, 80.0, GC.Spread.Sheets.SheetArea.viewport);

}

}

spread.resumeEvent();

spread.resumePaint();