Skip to main content Skip to footer

Sync the horizontal scrolling of two instances in JavaScript

Background:

To sync the horizontal scrolling of two instances, we must set the displayed left column of one instance to be the other instances' horizontal position. Using the LeftColumnChanged event, we can then set the HorizontalPosition of the other instance so that both sheets will scroll horizontally at the same time.

Steps to Complete:

Bind the LeftColumnChanged event of one instance to the left HorizontalPosition of the other instance

Getting Started:

Bind the LeftColumnChanged event of one instance to the left HorizontalPosition of the other spread instance.

var spread1 = new GC.Spread.Sheets.Workbook(document.getElementById("ss1"));
var sheet1 = spread1.getActiveSheet();

var spread2 = new GC.Spread.Sheets.Workbook(document.getElementById("ss2"));
var sheet2 = spread2.getActiveSheet();

sheet1.bind(GC.Spread.Sheets.Events.LeftColumnChanged, function(sender,args) {
  sheet2.showColumn(args.newLeftCol, GC.Spread.Sheets.HorizontalPosition.left);
});

Mackenzie Albitz