[]
        
(Showing Draft Content)

suspendEvent and resumeEvent

Whenever a user invokes the API in order to make changes to the data or modify existing style, the CellChanged event is fired. If the events are triggered repeatedly in short time frames, this process may cause a significant overhead which in turn leaves negative impact on the overall performance.


Therefore, it is recommended to use the suspendEvent method and resumeEvent method especially when you're planning to incorporate a lot of changes at once but don't want to trigger any of the Spread events.


The suspendEvent method stops the event processing until all the changes are complete and the resumeEvent method allows you to restore the event processing. Both of these methods are useful in order to enhance performance while working with events in SpreadJS.


Refer to the following code sample to use suspendEvent method and resumeEvent method to enhance performance while working with SpreadJS.

var spread = new GC.Spread.Sheets.Workbook(document.getElementById("ss"));
 var sheet = spread.getActiveSheet();
 spread.bind(GC.Spread.Sheets.Events.CellChanged, function (sender, args) {
 console.log('CellChanged event fired for Cell[' + args.row + "," + args.col + "] having value " + sheet.getValue(args.row, args.col));
 });
spread.suspendPaint();
spread.suspendEvent();
for (var i = 0; i < 20; i++) 
{
    for (var j = 0; j < 10; j++) 
    {
        sheet.setValue(i, j, "111");
    }
}
spread.resumeEvent();
spread.resumePaint();
/* The CellChanged event in this case will be fired for only Cell[22,2]
 and not for other cells because value of Cell[22, 2] is set after the bounds of suspendEvent() & resumeEvent() methods */
sheet.setValue(22, 2, "222");