Combining virtual scrolling with pagination in PrimeNG componentsCombining virtual scrolling and pagination is

I am currently facing a situation where I have to display 150 records simultaneously in my primeng data grid. However, the grid starts freezing after loading just 50 records. This is because there are 18 columns in my grid, causing it to consume a lot of memory. Additionally, there are many events attached to each row which further impacts performance. To address this issue, I believe implementing virtual scrolling would be ideal. The challenge, however, lies in making virtual scroll and pagination work together seamlessly within the grid. Any insights or solutions on how to overcome this hurdle would be greatly appreciated. Below is a snippet of the code I have experimented with so far, but it seems to be causing performance issues:

let element = this.elRef.nativeElement.querySelector('.ui-datatable-scrollable-body');
    this.zone.runOutsideAngular(() => {
        Observable.fromEvent(element, 'scroll')
            .debounceTime(20)
            .subscribe(res => {
                this.zone.run(() => {
                    let position = 0;
                    if (this.rowsCountPerPage > 10 && this.rowsCountPerPage > this.manualProcessGridData.length) {
                        let el = this.elRef.nativeElement.querySelector('.ui-datatable-scrollable-body');
                        let scroll = el.scrollTop;
                        if (el.scrollTop >= (el.scrollHeight - el.offsetHeight) * 0.7) {
                            if (scroll > position) {
                                let loopLength = this.lastElementInGrid + 10;
                                let loopStart = this.lastElementInGrid;
                                for (let i = loopStart; i <= loopLength; i++) {
                                    if (typeof this.docproData[i] !== 'undefined') {
                                        this.manualProcessGridData = [...this.manualProcessGridData, this.docproData[i]];
                                    }
                                    if (loopLength === i) {
                                        this.lastElementInGrid = i + 1;
                                    }
                                    if (i >= this.docproData.length) {
                                        break;
                                    }
                                }
                            }
                        }
                        position = scroll;
                    }
                });
        });
    });

Answer №1

Enhance your table's performance by dynamically setting the virtual scroll flag in your .ts file instead of hard-coding it to true or false.

Consider setting the virtual scroll flag to true for tables with more than 150 records, and false for tables with fewer than 50 records.

Similar questions

If you have not found the answer to your question or you are interested in this topic, then look at other similar questions below or use the search

Issue with the RxJS async pipe not functioning in a Reactive Development environment

Currently, I am in the process of learning reactive development in Angular by transforming my old methods in a service to work without subscribing at all in an Observable. So far, I have successfully converted the getAll method to this new approach. Now, m ...

What is the process for accessing a different view and its features on a separate screen using Angular portal?

In my angular project, I have multiple components. One component is being looped with an array using the following code: <body-chart *ngFor="..."></body-chart> Within the body-chart component : <div> <canvas id="canv ...

Anticipated request for spy navigation with path '/members' was expected, but unfortunately was not triggered

I am facing an issue with a service method that performs an HTTP delete operation. The expected behavior is that upon successful deletion, the page should be redirected to another location. However, during testing, I noticed that the router navigation func ...

When utilizing *ngIf in Angular 2, the issue of #elmentRef remaining undefined still persists

When using #elementReference with *ngIf in Angular 2, the element reference remains undefined even after the *ngIf expression evaluates to true. In this example, the value of the input will not be displayed. <input *ngIf="true" type="text" #myRef (inpu ...

How can you consistently emphasize data points in a line chart using NGRX?

I'm currently working with a line chart that displays line series. Is there any way to ensure all data points are highlighted at all times? Right now, the only time a data point is highlighted is when the mouse hovers over it. <ngx-charts-line ...

Receiving an error with React Proptypes when using the union type Breakpoint

Struggling to assign the correct proptype to the material-ui Breakpoint type. The breakpoint values are: export type Breakpoint = 'xs' | 'sm' | 'md' | 'lg' | 'xl'; In my App.tsx file, I have the following ...

Unable to instantiate a Vue reference with a potential null type

When working in Vue v3, I encountered a situation where I needed to create a ref with a type that could possibly be null. This specific scenario in my app involves data that starts off as null and then gets populated after loading completes. Just to illus ...

Looking for an IOS yearly calendar solution for Angular6? Look no further than the angular-calendar-year-view library available at [https://github.com/MariemChaab

Seeking an angular yearly calendar for iOS similar to the one found at [https://github.com/MariemChaabeni/angular-calendar-year-view], designed for use with Angular 7. However, when attempting to integrate it into Angular 6, I encountered error ts1005; e ...

NgFor conditional slice pipe

Is there a way to conditionally slice the output in an ngFor loop? Take a look at the snippet of HTML template below: <div *ngFor="let bucket of getBucketsWithValues(bucketName.criterium ? bucketName.criterium : bucketName) | orderBy:'key' ...

Issue with host-context scss rules not appearing in final production version

I am facing an issue in my Angular project where the scss rules that define how components should look when within the context of another component are not being applied when I build for production and put it live. Here is an example: :host-context(my-tabl ...

The repository's dependencies remain unresolved by Nest

I encountered an error in my nestjs application. Unfortunately, I am having trouble identifying the issue within my code snippet. Here is a glimpse of the relevant sections: AppModule import { Module } from '@nestjs/common'; import { TypeOrmMod ...

What is the correct way to incorporate service within a component function?

Here's how I'm implementing an inline input edit component: <app-inline-input-edit [label]="'Manufacturer'" [required]="true" [(ngModel)]="ctrlTypes.manufacturer" name="manufacturer" [changed]="onChange"> ...

Error message: Angular material StaticInjectorError - MatDialog provider not found

After trying to launch my Angular 5 page in the browser, I encountered an error message in the console. ERROR Error: StaticInjectorError(AppModule)[AppComponent -> MatDialog]: StaticInjectorError(Platform: core)[AppComponent -> MatDialog]: ...

How to retrieve the displayed text of a selected option in an Angular 7 reactive form dropdown control instead of the option value

Is there a way to retrieve the displayed text of the selected value in a drop-down list instead of just the value when using reactive forms? This is my current script: <form [formGroup]="formGroup" formArrayName="test"> <ng-container matColu ...

Issue with importing Typescript and Jquery - $ function not recognized

Currently, I am utilizing TypeScript along with jQuery in my project, however, I keep encountering the following error: Uncaught TypeError: $ is not a function Has anyone come across this issue before? The process involves compiling TypeScript to ES20 ...

Is it possible to assign a hashtag to a div in Angular 2?

Is it possible to bind the #theBody element from an array or variable instead of having a static reference to it when creating and injecting a component? import {ComponentRef, Injectable, Component, Injector, ViewContainerRef, ViewChild,ComponentResolver} ...

Show mistakes using source mapping (TypeScript combined with Node/Express)

In my Docker container, I have a node instance running express. Whenever I intentionally cause an error in my simple app.ts file, like below: // Start listening for requests app.listen(3000, () => { console.log('Application Service starting!&ap ...

Is there a way to set up a background process within electron that captures a screenshot of the entire desktop?

I'm currently working on a Desktop application using Angular2 and Electron that captures screenshots of the entire desktop and saves them to a specified path on my PC. The code for capturing screenshots is implemented in the app.component.ts file, but ...

After the initial test is executed, Jasmine's spy-on function proceeds to call the actual function

The issue arises when the second test fails due to an error message stating that "Cannot read property 'get' of undefined". This error occurs because the second test references the real service, which contains a private property called "http" tha ...

Tips for incorporating user access control logic into a lazy-loaded Angular Monorepo application without embedding the logic in the main application

In our current project, we are developing an Angular application utilizing the Angular monorepo structure. This setup includes a parent application and several children applications, with the parent application located in the `app` folder and the children ...