Scrolling in EJ2 JavaScript Spreadsheet control

2 May 20235 minutes to read

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 allowScrolling property 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 isFinite property as true.

  • Infinite - This mode creates a new row/column when the scrollbar reaches the end. This can be achieved by setting the isFinite property as false.

By Default, the isFinite property is false.

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 enableVirtualization property in scrollSettings as true.

In virtual scrolling enableVirtualization is set to true means, it allows you to load the spreadsheet data while scrolling.

By Default, the enableVirtualization property is true.

User Interface:

You can scroll through the worksheet using one of the following ways,

  • Using the arrow keys.
  • Using the Horizontal and Verticalscroll bars.
  • Using the mouse wheel.

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.

// Initialize the Spreadsheet component.

var columns = [
    {
        width: 130
    },
    {
        width: 92
    },
    {
        width: 96
    }
];

var spreadsheet = new ej.spreadsheet.Spreadsheet({
    sheets: [{ ranges: [{ dataSource: defaultData }], columns: columns }],
    allowScrolling: true,
    scrollSettings: { isFinite: true, enableVirtualization: false }
});

 

// Render 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/25.1.35/ej2-base/styles/material.css" rel="stylesheet">
        <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-inputs/styles/material.css" rel="stylesheet">
        <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-buttons/styles/material.css" rel="stylesheet">
        <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-splitbuttons/styles/material.css" rel="stylesheet">
        <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-lists/styles/material.css" rel="stylesheet">
        <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-navigations/styles/material.css" rel="stylesheet">
        <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-popups/styles/material.css" rel="stylesheet">
        <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-dropdowns/styles/material.css" rel="stylesheet">
        <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-grids/styles/material.css" rel="stylesheet">
        <link href="https://cdn.syncfusion.com/ej2/25.1.35/ej2-spreadsheet/styles/material.css" rel="stylesheet">
        <link href="styles.css" rel="stylesheet">
        
        <script src="https://cdnjs.cloudflare.com/ajax/libs/core-js/2.4.1/shim.min.js"></script>
        <script src="es5-datasource.js" type="text/javascript"></script>
<script src="https://cdn.syncfusion.com/ej2/25.1.35/dist/ej2.min.js" type="text/javascript"></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="container">
       <div id="spreadsheet"></div>
       </div>


<script>
var ele = document.getElementById('container');
if(ele) {
  ele.style.visibility = "visible";
}   
      </script>
<script src="index.js" type="text/javascript"></script>
</body></html>