Scrolling in EJ2 TypeScript Spreadsheet control
Scrolling helps you to move quickly to different areas of the worksheet. It moves faster if we use horizontal and vertical scroll bars. Scrolling can be enabled by setting the allowScrolling as true.
By default, the
allowScrollingproperty is true.
You have the following options in Scrolling by using scrollSettings.
- Finite scrolling.
- Virtual scrolling.
Finite Scrolling
Finite scrolling supports two type of modes in scrolling. You can use the isFinite property in scrollSettings to specify the mode of scrolling.
-
Finite - This mode does not create a new row/column when the scrollbar reaches the end. This can be achieved by setting the
isFiniteproperty astrue. -
Infinite - This mode creates a new row/column when the scrollbar reaches the end. This can be achieved by setting the
isFiniteproperty asfalse.
By Default, the
isFiniteproperty isfalse.
Virtual Scrolling
- Virtual scrolling allows you to load data that you require (load data based on viewport size) without buffering the entire huge database. You can set the
enableVirtualizationproperty inscrollSettingsastrue.
In virtual scrolling enableVirtualization is set to true means, it allows you to load the spreadsheet data while scrolling.
By Default, the
enableVirtualizationproperty istrue.
User Interface:
You can scroll through the worksheet using one of the following ways,
- Using the
arrowkeys. - Using the Horizontal and Vertical
scrollbars. - Using the
mousewheel.
Finite scrolling with defined rows and columns
If you want to perform scrolling with defined rows and columns, you must define rowCount and colCount in the sheets property and set isFinite as true and enableVirtualization as false in scrollSettings.
The following code example shows the finite scrolling with defined rows and columns in the spreadsheet. Here, we used rowCount as 20 and colCount as 20, after reaching the 20th row or 20th column you can’t able to scroll.
import { Spreadsheet, ColumnModel } from '@syncfusion/ej2-spreadsheet';
import { defaultData } from './datasource.ts';
let columns: ColumnModel[] = [
{
width: 100
},
{
width: 92
},
{
width: 96
},
{
width: 110
},
{
width: 92
},
{
width: 96
},
{
width: 96
}
];
let spreadsheet: Spreadsheet = new Spreadsheet({
sheets: [{ name: 'Price Details', ranges: [{ dataSource: defaultData }], columns: columns, rowCount: 9, colCount: 7 }],
allowScrolling: true,
scrollSettings: { isFinite: true },
created: (): void => {
spreadsheet.cellFormat({ fontWeight: 'bold', textAlign: 'center', verticalAlign: 'middle' }, 'A1:G1');
}
});
//Render the initialized Spreadsheet
spreadsheet.appendTo('#spreadsheet');<!DOCTYPE html>
<html lang="en">
<head>
<title>EJ2 SpreadSheet</title>
<meta charset="utf-8" />
<meta name="viewport" content="width=device-width, initial-scale=1.0" />
<meta name="description" content="Typescript UI Controls" />
<meta name="author" content="Syncfusion" />
<link rel="shortcut icon" href="resources/favicon.ico" />
<link href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-base/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-inputs/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-buttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-splitbuttons/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-lists/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-navigations/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-popups/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-dropdowns/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-grids/styles/material.css" rel="stylesheet" />
<link href="https://cdn.syncfusion.com/ej2/31.2.2/ej2-spreadsheet/styles/material.css" rel="stylesheet" />
<link href="styles.css" rel="stylesheet" />
<script src="https://cdnjs.cloudflare.com/ajax/libs/systemjs/0.19.38/system.js"></script>
<script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/shim.min.js"></script>
<script src="system.config.js"></script>
<script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/syncfusion-helper.js" type ="text/javascript"></script>
</head>
<body>
<!--Element which is going to render-->
<div id='loader'>Loading....</div>
<div id='container'>
<div id="spreadsheet"></div>
</div>
</body>
</html>