Scrolling in Angular Spreadsheet component
27 Apr 20245 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 astrue
. -
Infinite - This mode creates a new row/column when the scrollbar reaches the end. This can be achieved by setting the
isFinite
property asfalse
.
By Default, the
isFinite
property 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
enableVirtualization
property inscrollSettings
astrue
.
In virtual scrolling enableVirtualization
is set to true means, it allows you to load the spreadsheet data while scrolling.
By Default, the
enableVirtualization
property istrue
.
User Interface:
You can scroll through the worksheet using one of the following ways,
- Using the
arrow
keys. - Using the Horizontal and Vertical
scroll
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.
import { NgModule } from '@angular/core'
import { BrowserModule } from '@angular/platform-browser'
import { SpreadsheetAllModule } from '@syncfusion/ej2-angular-spreadsheet'
import { Component, ViewChild } from '@angular/core';
import { SpreadsheetComponent } from '@syncfusion/ej2-angular-spreadsheet';
import { enableRipple } from '@syncfusion/ej2-base';
import { dataSource1 } from './datasource';
enableRipple(true);
@Component({
imports: [
SpreadsheetAllModule
],
standalone: true,
selector: 'app-container',
template: `<ejs-spreadsheet #spreadsheet (created)="created()" [allowScrolling]="true" [scrollSettings]="{ isFinite: true }">
<e-sheets>
<e-sheet name="Price Details" rowCount="9" colCount="7">
<e-ranges>
<e-range [dataSource]="priceData"></e-range>
</e-ranges>
<e-columns>
<e-column [width]=130></e-column>
<e-column [width]=92></e-column>
<e-column [width]=96></e-column>
<e-column [width]=130></e-column>
<e-column [width]=92></e-column>
<e-column [width]=96></e-column>
<e-column [width]=96></e-column>
</e-columns>
</e-sheet>
</e-sheets>
</ejs-spreadsheet>`
})
export class AppComponent {
@ViewChild('spreadsheet')
spreadsheetObj: SpreadsheetComponent | undefined;
priceData: object[] = dataSource1;
created() {
this.spreadsheetObj!.cellFormat({ fontWeight: 'bold', textAlign: 'center' }, 'A1:H1');
}
}
import { bootstrapApplication } from '@angular/platform-browser';
import { AppComponent } from './app.component';
import 'zone.js';
bootstrapApplication(AppComponent).catch((err) => console.error(err));
Note
You can refer to our Angular Spreadsheet feature tour page for its groundbreaking feature representations. You can also explore our Angular Spreadsheet example to knows how to present and manipulate data.