Why Implement Infinite Scrolling for Web Needs, When It Is Available Ready-Made? | Syncfusion Blogs
Live Chat Icon For mobile
Live Chat Icon
Popular Categories.NET  (174).NET Core  (29).NET MAUI  (207)Angular  (109)ASP.NET  (51)ASP.NET Core  (82)ASP.NET MVC  (89)Azure  (41)Black Friday Deal  (1)Blazor  (219)BoldSign  (14)DocIO  (24)Essential JS 2  (107)Essential Studio  (200)File Formats  (66)Flutter  (133)JavaScript  (221)Microsoft  (119)PDF  (81)Python  (1)React  (101)Streamlit  (1)Succinctly series  (131)Syncfusion  (918)TypeScript  (33)Uno Platform  (3)UWP  (4)Vue  (45)Webinar  (51)Windows Forms  (61)WinUI  (68)WPF  (159)Xamarin  (161)XlsIO  (36)Other CategoriesBarcode  (5)BI  (29)Bold BI  (8)Bold Reports  (2)Build conference  (8)Business intelligence  (55)Button  (4)C#  (149)Chart  (131)Cloud  (15)Company  (443)Dashboard  (8)Data Science  (3)Data Validation  (8)DataGrid  (63)Development  (632)Doc  (8)DockingManager  (1)eBook  (99)Enterprise  (22)Entity Framework  (5)Essential Tools  (14)Excel  (40)Extensions  (22)File Manager  (7)Gantt  (18)Gauge  (12)Git  (5)Grid  (31)HTML  (13)Installer  (2)Knockout  (2)Language  (1)LINQPad  (1)Linux  (2)M-Commerce  (1)Metro Studio  (11)Mobile  (507)Mobile MVC  (9)OLAP server  (1)Open source  (1)Orubase  (12)Partners  (21)PDF viewer  (43)Performance  (12)PHP  (2)PivotGrid  (4)Predictive Analytics  (6)Report Server  (3)Reporting  (10)Reporting / Back Office  (11)Rich Text Editor  (12)Road Map  (12)Scheduler  (52)Security  (3)SfDataGrid  (9)Silverlight  (21)Sneak Peek  (31)Solution Services  (4)Spreadsheet  (11)SQL  (11)Stock Chart  (1)Surface  (4)Tablets  (5)Theme  (12)Tips and Tricks  (112)UI  (387)Uncategorized  (68)Unix  (2)User interface  (68)Visual State Manager  (2)Visual Studio  (31)Visual Studio Code  (19)Web  (596)What's new  (333)Windows 8  (19)Windows App  (2)Windows Phone  (15)Windows Phone 7  (9)WinRT  (26)
Why Implement Infinite Scrolling for Web Needs, When It Is Available Ready-Made?

Why Implement Infinite Scrolling for Web Needs, When It Is Available Ready-Made?

Infinite scrolling is about visualizing huge amounts of data in a single window that doesn’t end. Usually in infinite scrolling, data is fetched on demand when the scroll head reaches the bottom of the window.

Infinite scrolling in DataGrid works in a similar way. Initially, a part of the data is displayed in the grid, and when a user scrolls down to the bottom of it, an additional query is made, and the fetched data is appended. So, we can load a huge amount of data without degrading the DataGrid performance. Infinite scrolling is an alternative to paging, where the newly queried data is displayed in new pages.

Some of the most common examples of infinite scrolling are:

  • Scrolling through Twitter tweets
  • Scrolling through Facebook posts
  • Google Image search

In this blog post, we will show you how easily you can visualize huge amounts of data in a single grid view using the infinite scrolling feature in our Angular Data Grid.

Why we use infinite scrolling

Infinite scrolling provides a great user experience, it efficiently queries only the data necessary, and it reduces the number of data reads from the server back and forth.

JS2 DataGrid infinite scrolling with templates
JS2 DataGrid infinite scrolling with templates

What is special about infinite scrolling in EJ2 DataGrid?

All modern browsers have a hard limit on the amount of memory allocated to a particular webpage and browsers are not designed to handle millions of elements.

Due to this browser limitation, when continuously appending data to a grid component, the browser will go unresponsive. This is due to the gradual increase in the DOM weightage and browser memory.

To overcome this problem, our DataGrid is provided with a cache mode option. When enabling this feature, DataGrid will maintain row elements based on the maxBlocks count value of the infiniteScrollSettings. Once this limit is reached, DataGrid will remove row elements only from DOM and maintain the data on the grid instance.

Steps to implement infinite scrolling with frozen grid in Angular environment

Step 1: Set up Angular environment

Use Angular CLI to set up your Angular applications. To install Angular CLI, use the following command.

npm install -g @angular/cli

Step 2: Create an Angular application

Start a new Angular application using the following Angular CLI command.

ng new my-app
cd my-app

Step 3: Add the Syncfusion Grid package

All the Essential JS 2 NuGet packages are published in the npmjs.com registry.

To install the Data Grid component, use the following command.

npm install @syncfusion/ej2-angular-grids --save

The —save will instruct NPM to include the grid package inside of the dependencies section of the package.json.

Step 4: Registering Grid module

Import the Grid module into the Angular application (app.module.ts) from the package @syncfusion/ej2-angular-grids [src/app/app.module.ts].

import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
// import the GridModule for the Grid component
import { GridModule } from '@syncfusion/ej2-angular-grids';
import { AppComponent }  from './app.component';

@NgModule({
  //declaration of ej2-angular-grids module into NgModule
  imports:      [ BrowserModule, GridModule ],
  declarations: [ AppComponent ],
  bootstrap:    [ AppComponent ]
})
export class AppModule { }

Step 5: Adding CSS reference

The following CSS files are available in the ../node_modules/@syncfusion package folder. Add reference to these CSS files in styles.css[src/styles.css] using the following code.

@import '../node_modules/@syncfusion/ej2-base/styles/material.css';  
@import '../node_modules/@syncfusion/ej2-buttons/styles/material.css';  
@import '../node_modules/@syncfusion/ej2-calendars/styles/material.css';  
@import '../node_modules/@syncfusion/ej2-dropdowns/styles/material.css';  
@import '../node_modules/@syncfusion/ej2-inputs/styles/material.css';  
@import '../node_modules/@syncfusion/ej2-navigations/styles/material.css';
@import '../node_modules/@syncfusion/ej2-popups/styles/material.css';
@import '../node_modules/@syncfusion/ej2-splitbuttons/styles/material.css';  
@import '../node_modules/@syncfusion/ej2-angular-grids/styles/material.css';

Step 6: Add the Data Grid component

Modify the template in the [src/app/app.component.ts] file to render the grid component. Add the Angular Data Grid by using the <ejs-grid> selector in the template section of the app.component.ts file.

import { Component, OnInit } from '@angular/core';

@Component({
  selector: 'app-root',
  // specifies the template string for the Grid component
  template: `<ejs-grid> </ejs-grid>`
})
export class AppComponent implements OnInit {

    ngOnInit(): void {
    }
}

Step 7: Defining dataSource and columns

Bind the data to the Data Grid component by using dataSource property. It either accepts an array of JavaScript objects or a DataManager instance. Then define columns based on the properties of the dataSource.

import { Component, OnInit } from '@angular/core';
import { getData } from './datasource';

@Component({
  selector: 'app-root',
  template: `<ejs-grid [dataSource]='data'>
                <e-columns>
                    <e-column field='TaskID' headerText='Task ID' textAlign='Right' width=90></e-column>
                    <e-column field='Engineer' headerText='Engineer' width=120></e-column>
                    <e-column field='Designation' headerText='Designation'width=120></e-column>
                    <e-column field='Estimation' headerText='Estimation' textAlign='Right' width=120></e-column>
                    <e-column field='Status' headerText='Status'width=120></e-column>
                </e-columns>
                </ejs-grid>`
})

export class AppComponent implements OnInit {

  public data: object[];

  ngOnInit(): void {
    this.data = getData(10000);
  }
}

Step 8: Module injection

To create a grid with additional features, inject the required modules. The following modules are used to extend the grid’s basic functionality:

  • InfiniteScrollService: Inject this provider to use the infinite scrolling feature.
  • FreezeService: Inject this provider to use the frozen rows and columns feature.

These modules should be injected into the provider’s section of the root NgModule or component class.

Step 9: Enable infinite scrolling

The infinite scrolling feature can be enabled by setting the enableInfiniteScrolling property to true. Also, we have to inject the InfiniteScrollService module in the provider section.

Step 10: Set frozen columns

Frozen columns can be defined using the frozenColumns property. Also, inject the FreezeService module in the provider section.

import { Component, OnInit } from '@angular/core';
import { getData } from './datasource';

@Component({
  selector: 'app-root',
  template: `<ejs-grid [dataSource]='data' height=300 [enableInfiniteScrolling]='true' [frozenColumns]='2'>
                <e-columns>
                    <e-column field='TaskID' headerText='Task ID' textAlign='Right' width=90></e-column>
                    <e-column field='Engineer' headerText='Engineer' width=120></e-column>
                    <e-column field='Designation' headerText='Designation'width=120></e-column>
                    <e-column field='Estimation' headerText='Estimation' textAlign='Right' width=120></e-column>
                    <e-column field='Status' headerText='Status'width=120></e-column>
                </e-columns>
                </ejs-grid>`
})

export class AppComponent implements OnInit {

  public data: object[];

  ngOnInit(): void {
    this.data = getData(10000);
  }
}

Step 11: Run the application

Use the following command to run the application in the browser.

ng serve --open

The output will appear as shown in the following screenshot.
Output

Resource

You can download this application from this GitHub location.

Conclusion

I hope you now have a clear idea about the infinite scrolling feature and how to use it in the Syncfusion EJ2 DataGrid. This feature is available from the 2020 Volume 2 release.

If you are already a customer, you can download our Angular package from the License and Downloads page. If you are not yet a customer, you can try our 30-day free trial to check out all our Angular components have to offer. You can also explore samples in our GitHub repository.

If you have any questions about this blog, please let us know in the comments section below. You can also contact us through our support forumDirect-Trac, or feedback portal. We are always happy to assist you!

Tags:

Share this post:

Comments (2)

Great article with very useful information. Is it only for Angular or does the Blazor SFGrid gets it too ?

Hi Ben,
Currently, the infinite scrolling feature is available in all the other platforms except Blazor. We will consider this feature request in our Volume 4, 2020 release roadmap.

Comments are closed.

Popular Now

Be the first to get updates

Subscribe RSS feed

Be the first to get updates

Subscribe RSS feed