Viewport

The viewport delimits the area of the visible cells in the JavaScript grid. When the viewport is enabled, JSS will render only the necessary visible cells. That means viewport is the most important configuration when dealing with a large amount of data.

tableOverflow: true will enable the viewport along the properties tableWidth and tableHeight to define the viewport width and height respectively. It is also possible to use fullscreen: true to make sure all available screen area is used for cell rendering.

Those properties are defined at the worksheet level. That means the developer can choose different viewport sizes for each worksheet.

Documentation

Methods

The following methods interact with the worksheets viewport programmatically.
MethodDescription
setViewportinstance.setViewport(w: Number, h: Number) => void
fullscreeninstance.fullscreen(state: Boolean) => void
gotoinstance.goto(y: Number, x?: Number) => void
leftinstance.left(shiftKey?: Boolean, ctrlKey?: Boolean, jump?: Boolean) => void
topinstance.top(shiftKey?: Boolean, ctrlKey?: Boolean, jump?: Boolean) => void
rightinstance.right(shiftKey?: Boolean, ctrlKey?: Boolean, jump?: Boolean) => void
downinstance.down(shiftKey?: Boolean, ctrlKey?: Boolean, jump?: Boolean) => void
lastinstance.last(shiftKey?: Boolean, ctrlKey?: Boolean) => void
firstinstance.first(shiftKey?: Boolean, ctrlKey?: Boolean) => void


Settings

Related settings.
PropertyDescription
tableOverflow: booleanEnable the spreadsheet viewport.
tableWidth: numberSpreadsheet viewport width.
tableHeight: numberSpreadsheet Viewport height.
resize: stringEnable resizable viewport.
fullscreen: booleanFullscreen viewport.
virtualizationX: booleanEnable virtualization on the columns. Default true.
virtualizationY: booleanEnable virtualization on the rows. Default true.


Events

Related events.
MethodDescription
onresizeonresize(worksheet: Object, w: number, h: number) => void


Example

Change the spreadsheet viewport dimensions

The following example changes the visible viewport area dynamically.





Source code

<html>
<script src="https://jspreadsheet.com/v9/jspreadsheet.js"></script>
<link rel="stylesheet" href="https://jspreadsheet.com/v9/jspreadsheet.css" type="text/css" />
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />

<div id="spreadsheet"></div>

<input type="text" value="800px" style="width:60px" />
<input type="text" value="400px" style="width:60px" />
<input type="button" value="Set viewport" onclick="setViewport(this)" />
<input type="button" value="Set fullscreen" onclick="grid[0].fullscreen(true)" />

<script>
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('MzFiZjM4ODUwMGY2YzJiMjY2ZmI0M2JhNDdmMDY4YTliMDg5MDJlZjM2NDhhZTgxOWY3OGY4ZmI1NTlmMDg3MGNkZGM5Nzg4ZjYxZWUyZjAxNjQ5OGVhMmQzY2RhZTUxZmJmODRkNTJlMWFjYjg1MTQ4YTIzNjc0YjcwOWUyODIsZXlKdVlXMWxJam9pU25Od2NtVmhaSE5vWldWMElpd2laR0YwWlNJNk1UY3hNRGt3TVRBeU55d2laRzl0WVdsdUlqcGJJbXB6Y0hKbFlXUnphR1ZsZEM1amIyMGlMQ0pqYjJSbGMyRnVaR0p2ZUM1cGJ5SXNJbXB6YUdWc2JDNXVaWFFpTENKamMySXVZWEJ3SWl3aWQyVmlJaXdpYkc5allXeG9iM04wSWwwc0luQnNZVzRpT2lJek5DSXNJbk5qYjNCbElqcGJJblkzSWl3aWRqZ2lMQ0oyT1NJc0luWXhNQ0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklsMHNJbVJsYlc4aU9uUnlkV1Y5');

// Create the spreadsheet
function setViewport = function(o) {
    // First worksheet
    grid[0].setViewport(o.previousElementSibling.previousElementSibling.value, o.previousElementSibling.value);
}

var data = [];

// Create the data
for (var j = 0; j < 500; j++) {
     data[j] = [];
     for (var i = 0; i < 20; i++) {
         data[j][i] = jspreadsheet.helpers.getColumnNameFromCoords(i, j);
     }
}

var grid = jspreadsheet(document.getElementById('spreadsheet'), {
    toolbar: true,
    worksheets: [{
        data: data,
        tableOverflow: true,
        tableWidth: '600px',
        // Enable resize on both directions
        resize: 'both',
    }]
});
</script>
</html>


Goto

Move the viewport to a specified row or cell.





Source code

<html>
<script src="https://jspreadsheet.com/v9/jspreadsheet.js"></script>
<link rel="stylesheet" href="https://jspreadsheet.com/v9/jspreadsheet.css" type="text/css" />
<script src="https://jsuites.net/v5/jsuites.js"></script>
<link rel="stylesheet" href="https://jsuites.net/v5/jsuites.css" type="text/css" />

<link rel="stylesheet" href="https://fonts.googleapis.com/css?family=Material+Icons" />

<div id="spreadsheet"></div>

<input type="button" value="Goto row number 500" onclick="grid[0].goto(499)" />

<script>
// Set your JSS license key (The following key only works for one day)
jspreadsheet.setLicense('MzFiZjM4ODUwMGY2YzJiMjY2ZmI0M2JhNDdmMDY4YTliMDg5MDJlZjM2NDhhZTgxOWY3OGY4ZmI1NTlmMDg3MGNkZGM5Nzg4ZjYxZWUyZjAxNjQ5OGVhMmQzY2RhZTUxZmJmODRkNTJlMWFjYjg1MTQ4YTIzNjc0YjcwOWUyODIsZXlKdVlXMWxJam9pU25Od2NtVmhaSE5vWldWMElpd2laR0YwWlNJNk1UY3hNRGt3TVRBeU55d2laRzl0WVdsdUlqcGJJbXB6Y0hKbFlXUnphR1ZsZEM1amIyMGlMQ0pqYjJSbGMyRnVaR0p2ZUM1cGJ5SXNJbXB6YUdWc2JDNXVaWFFpTENKamMySXVZWEJ3SWl3aWQyVmlJaXdpYkc5allXeG9iM04wSWwwc0luQnNZVzRpT2lJek5DSXNJbk5qYjNCbElqcGJJblkzSWl3aWRqZ2lMQ0oyT1NJc0luWXhNQ0lzSW1Ob1lYSjBjeUlzSW1admNtMXpJaXdpWm05eWJYVnNZU0lzSW5CaGNuTmxjaUlzSW5KbGJtUmxjaUlzSW1OdmJXMWxiblJ6SWl3aWFXMXdiM0owWlhJaUxDSmlZWElpTENKMllXeHBaR0YwYVc5dWN5SXNJbk5sWVhKamFDSXNJbkJ5YVc1MElpd2ljMmhsWlhSeklsMHNJbVJsYlc4aU9uUnlkV1Y5');

// Create the spreadsheet
var grid = jspreadsheet(document.getElementById('spreadsheet'), {
    worksheets: [{
        minDimensions: [6, 5000],
        tableOverflow: true,
        tableWidth: '600px',
    }]
});
</script>
</html>