Open In App

Angular PrimeNG Tree Scroll

Last Updated : 10 Oct, 2022
Improve
Improve
Like Article
Like
Save
Share
Report

Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the Tree Scroll in Angular PrimeNG.

Angular PrimeNG Tree Scroll is used to enable scroll in the Tree Component. Scroller is an efficient approach to handling data effectively. We can easily add a scroller to show the data in a scrollable way.

Syntax:

<p-tree 
    [value]="..." 
    scrollHeight="...">
</p-tree>

 

Angular PrimeNG Tree Scroll properties:

  • scrollHeight: It is used to define the height of the scrollable viewport. It is a string type and its default value is null.
  • value: It is used to define the array of all the tree nodes. It is an array type and its default value is null.

Creating Angular application & Module Installation:

Step 1: Create an Angular application using the following command.

ng new appname

Step 2: After creating your project folder i.e. appname, move to it using the following command.

cd appname

Step 3: Install PrimeNG in your given directory.

npm install primeng --save
npm install primeicons --save

Project Structure: It will look like the following:

 

Example 1: Below is a simple example demonstrating the use of the Angular PrimeNG TreeTable Scroll.

  • app.component.html

HTML




<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Tree Scroll</h4>
<p-tree [value]="files1" scrollHeight="300px"> </p-tree>


  • app.component.ts

Javascript




import { Component, OnInit } from '@angular/core';
import { TreeNode } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent {
    files1: TreeNode[] = [];
  
    constructor() { }
  
    ngOnInit() {
        this.files1 = [
            { label: 'Z', icon: 'pi pi-folder' },
            { label: 'A', icon: 'pi pi-folder' },
            { label: 'D', icon: 'pi pi-folder' },
            { label: 'C', icon: 'pi pi-folder' },
            { label: 'W', icon: 'pi pi-folder' },
            { label: 'E', icon: 'pi pi-folder' },
            { label: 'R', icon: 'pi pi-folder' },
            { label: 'G', icon: 'pi pi-folder' },
            { label: 'K', icon: 'pi pi-folder' },
  
            {
                label: 'A',
                icon: 'pi pi-folder',
  
                children: [
                    {
                        label: 'B',
                        icon: 'pi pi-folder',
  
                        children: [
                            {
                                label: 'C',
                                icon: 'pi pi-folder',
                            },
                            {
                                label: 'D',
                                icon: 'pi pi-folder',
                            },
                        ],
                    },
                    {
                        label: 'E',
                        icon: 'pi pi-folder',
  
                        children: [
                            {
                                label: 'F',
                                icon: 'pi pi-folder',
                            },
                        ],
                    },
                ],
            },
            {
                label: 'G',
                icon: 'pi pi-folder',
  
                children: [
                    {
                        label: 'H',
                        icon: 'pi pi-folder',
                    },
                    {
                        label: 'I',
                        icon: 'pi pi-folder',
                    },
                    {
                        label: 'J',
                        icon: 'pi pi-folder',
                    },
                ],
            },
        ];
    }
}


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule }
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { TreeModule } from 'primeng/tree';
import { ButtonModule } from 'primeng/button';
import { InputTextModule } from 'primeng/inputtext';
import { VirtualScrollerModule }
    from 'primeng/virtualscroller';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TreeModule,
        ButtonModule,
        InputTextModule,
        HttpClientModule,
        FormsModule,
        VirtualScrollerModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [],
})
export class AppModule { }


Output:

 

Example 2: Below is a simple example demonstrating the use of the Angular PrimeNG TreeTable Scroll.

  • app.component.html

HTML




<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Tree Scroll</h4>
<p-tree [value]="files1" scrollHeight="200px"> </p-tree>


  • app.component.ts

Javascript




import { Component, OnInit } from '@angular/core';
import { TreeNode } from 'primeng/api';
  
@Component({
    selector: 'app-root',
    templateUrl: './app.component.html',
})
export class AppComponent {
    files1: TreeNode[] = [];
  
    constructor() { }
  
    ngOnInit() {
        this.files1 = [
            { label: 'Z', icon: 'pi pi-folder' },
            { label: 'A', icon: 'pi pi-folder' },
            { label: 'D', icon: 'pi pi-folder' },
            { label: 'C', icon: 'pi pi-folder' },
            { label: 'W', icon: 'pi pi-folder' },
            { label: 'E', icon: 'pi pi-folder' },
            { label: 'R', icon: 'pi pi-folder' },
            { label: 'G', icon: 'pi pi-folder' },
            { label: 'K', icon: 'pi pi-folder' },
  
            {
                label: 'A',
                icon: 'pi pi-folder',
  
                children: [
                    {
                        label: 'B',
                        icon: 'pi pi-folder',
  
                        children: [
                            {
                                label: 'C',
                                icon: 'pi pi-folder',
                            },
                            {
                                label: 'D',
                                icon: 'pi pi-folder',
                            },
                        ],
                    },
                    {
                        label: 'E',
                        icon: 'pi pi-folder',
  
                        children: [
                            {
                                label: 'F',
                                icon: 'pi pi-folder',
                            },
                        ],
                    },
                ],
            },
            {
                label: 'G',
                icon: 'pi pi-folder',
  
                children: [
                    {
                        label: 'H',
                        icon: 'pi pi-folder',
                    },
                    {
                        label: 'I',
                        icon: 'pi pi-folder',
                    },
                    {
                        label: 'J',
                        icon: 'pi pi-folder',
                    },
                ],
            },
        ];
    }
}


  • app.module.ts

Javascript




import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { HttpClientModule } from '@angular/common/http';
import { BrowserAnimationsModule } 
    from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { TreeModule } from 'primeng/tree';
import { ButtonModule } from 'primeng/button';
import { InputTextModule } from 'primeng/inputtext';
import { VirtualScrollerModule } 
    from 'primeng/virtualscroller';
  
@NgModule({
    imports: [
        BrowserModule,
        BrowserAnimationsModule,
        TreeModule,
        ButtonModule,
        InputTextModule,
        HttpClientModule,
        FormsModule,
        VirtualScrollerModule
    ],
    declarations: [AppComponent],
    bootstrap: [AppComponent],
    providers: [],
})
export class AppModule { }


Output:

 

Reference: https://primefaces.org/primeng/tree/scroll



Similar Reads

Angular PrimeNG Tree Flex Scroll
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Tree Flex Scroll in Angular PrimeNG. Angular PrimeNG Tree Flex Scroll is used in cases where viewport should adju
5 min read
Angular PrimeNG Table Full Page Scroll
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Table Full Page Scroll in Angular PrimeNG. Angular PrimeNG Table Full Page Scroll enables Full Page Viewport scro
5 min read
Angular PrimeNG TreeTable Scroll
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use TreeTable Scrolling in Angular PrimeNG. Angular PrimeNG TreeTable Scroll enables scroll in the TreeTable componen
8 min read
Angular PrimeNG TreeTable Full Page Scroll
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use TreeTable Full Page Scroll in Angular PrimeNG. Angular PrimeNG TreeTable Full Page Scroll enables Full Page Viewp
7 min read
Angular PrimeNG Table Scroll Layout
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Angular PrimeNG Table Scroll Layout. The Table Component shows some data to the user in tabular form. To enable s
4 min read
Angular PrimeNG TreeTable Flex Scroll
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use TreeTable Flex Scroll in Angular PrimeNG. Angular PrimeNG TreeTable Flex Scroll enables Flex Scroller in the Tree
6 min read
Angular PrimeNG Table Flex Scroll
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Table Flex Scroll in Angular PrimeNG. Angular PrimeNG Table Flex Scroll enables Flex Scroller in the Table compon
6 min read
Angular PrimeNG Carousel Items Per Page and Scroll Items
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Carousel in Angular PrimeNG. Angular PrimeNG Basic Carousel is used to render the basic carousel. The carousel is
4 min read
Angular PrimeNG DataTable Scroll
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use Table Scroll in Angular PrimeNG. The Table Component shows some data to the user in tabular form. The DataTable s
7 min read
Angular PrimeNG Form Dropdown Virtual Scroll Component
Angular PrimeNG is an open-source framework with a rich set of native Angular UI components that are used for great styling and this framework is used to make responsive websites with very much ease. This article will show us how to use the Form Dropdown Virtual Scroll Component in Angular PrimeNG. The Virtual Scroll Component is used to create a v
4 min read