Skip to content
geeksforgeeks
  • Courses
    • DSA to Development
    • Get IBM Certification
    • Newly Launched!
      • Master Django Framework
      • Become AWS Certified
    • For Working Professionals
      • Interview 101: DSA & System Design
      • Data Science Training Program
      • JAVA Backend Development (Live)
      • DevOps Engineering (LIVE)
      • Data Structures & Algorithms in Python
    • For Students
      • Placement Preparation Course
      • Data Science (Live)
      • Data Structure & Algorithm-Self Paced (C++/JAVA)
      • Master Competitive Programming (Live)
      • Full Stack Development with React & Node JS (Live)
    • Full Stack Development
    • Data Science Program
    • All Courses
  • Tutorials
    • Data Structures & Algorithms
    • ML & Data Science
    • Interview Corner
    • Programming Languages
    • Web Development
    • CS Subjects
    • DevOps And Linux
    • School Learning
  • Practice
    • Build your AI Agent
    • GfG 160
    • Problem of the Day
    • Practice Coding Problems
    • GfG SDE Sheet
  • Contests
    • Accenture Hackathon (Ending Soon!)
    • GfG Weekly [Rated Contest]
    • Job-A-Thon Hiring Challenge
    • All Contests and Events
  • AngularJS Tutorial
  • AngularJS Directives
  • AngularJS Functions
  • AngularJS Filters
  • AngularJS Examples
  • AngularJS Interview Questions
  • Angular ngx Bootstrap
  • AngularJS Cheat Sheet
  • AngularJS PrimeNG
  • JavaScript
  • Web Technology
Open In App
Next Article:
Angular PrimeNG TreeTable - Responsive
Next article icon

Angular PrimeNG TreeTable Column Resize

Last Updated : 07 Sep, 2022
Comments
Improve
Suggest changes
Like Article
Like
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 TreeTable Column Resize in Angular PrimeNG.

Angular PrimeNG TreeTable Column Resize enables resizing of columns in the TreeTable component. Columns can be resized and their width can be easily changed using templating which makes the table More Interactive and user-friendly.

Syntax:

<p-treeTable       [columns]="cols"       [value]="tableData"       [resizableColumns]="true">            <ng-template pTemplate="colgroup" let-columns>          ...      </ng-template>        <ng-template pTemplate="header" let-columns>          ...      </ng-template>        <ng-template pTemplate="body"           let-rowNode let-rowData="rowData"           let-columns="columns">              ...      </ng-template>  </p-treeTable>

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:

Project Structure

Example 1: Below is a simple example that demonstrates the use of the Angular PrimeNG TreeTable Column Resize. In this example, we are setting the resizbleColumns property to "true" to resize the columns.

app.component.html
<div style="height: calc(100vh - 149px)">     <h2 style="color: green">GeeksforGeeks</h2>     <h4>Angular PrimeNG TreeTable Column Resize</h4>      <p-treeTable          [columns]="cols"          [value]="tableData"          [resizableColumns]="true">         <ng-template pTemplate="colgroup" let-columns>             <colgroup>                 <col *ngFor="let col of columns" />             </colgroup>         </ng-template>          <ng-template pTemplate="header" let-columns>             <tr>                 <th *ngFor="let col of columns"                      ttResizableColumn>                     {{ col.header }}                 </th>             </tr>         </ng-template>          <ng-template              pTemplate="body"              let-rowNode              let-rowData="rowData"              let-columns="columns">             <tr>                 <td *ngFor="let col of columns; let i = index">                     <p-treeTableToggler [rowNode]="rowNode"                                          *ngIf="i == 0">                     </p-treeTableToggler>                     {{ rowData[col.field] }}                 </td>             </tr>         </ng-template>     </p-treeTable> </div> 
app.component.ts
import { Component, OnInit } from '@angular/core'; import { NodeService } from './nodeservice'; import { TreeNode } from 'primeng/api';  @Component({     selector: 'app-root',     templateUrl: './app.component.html', }) export class AppComponent {     tableData: TreeNode[] = [];     cols: any[] = [];     constructor(private nodeService: NodeService) { }      ngOnInit() {         this.cols = [             { field: 'firstname', header: 'First Name' },             { field: 'lastname', header: 'Last Name' },              { field: 'age', header: 'Age' },         ];         this.tableData = [             {                 data: {                     firstname: 'David',                     lastname: 'ace',                     age: '40',                 },                 children: [                     {                         data: {                             firstname: 'Nathan',                             lastname: 'ace',                              age: '16',                         },                         children: [                             {                                 data: {                                     firstname: 'Abe',                                     lastname: 'ace',                                      age: '12',                                 },                             },                             {                                 data: {                                     firstname: 'Ksi',                                     lastname: 'ace',                                      age: '12',                                 },                             },                         ],                     },                     {                         data: {                             firstname: 'Shane',                             lastname: 'ace',                              age: '14',                         },                     },                 ],             },             {                 data: {                     firstname: 'Warner',                     lastname: 'ace',                      age: '55',                 },                 children: [                     {                         data: {                             lastname: 'ace',                             firstname: 'Michelle',                             age: '20',                         },                     },                     {                         data: {                             firstname: 'Charlie',                             lastname: 'ace',                              age: '24',                         },                     },                 ],             },             {                 data: {                     firstname: 'Max',                     lastname: 'ace',                      age: '55',                 },                 children: [                     {                         data: {                             firstname: 'Michelle',                             lastname: 'ace',                              age: '20',                         },                     },                     {                         data: {                             firstname: 'Charlie',                             lastname: 'ace',                              age: '24',                         },                     },                 ],             },             {                 data: {                     firstname: 'Willy',                     lastname: 'ace',                      age: '55',                 },                 children: [                     {                         data: {                             firstname: 'Michelle',                             lastname: 'ace',                              age: '20',                         },                     },                     {                         data: {                             firstname: 'Charlie',                             lastname: 'ace',                              age: '24',                         },                     },                 ],             },             {                 data: {                     firstname: 'Miley',                     lastname: 'ace',                      age: '55',                 },                 children: [                     {                         data: {                             firstname: 'Michelle',                             lastname: 'ace',                              age: '20',                         },                     },                     {                         data: {                             firstname: 'Charlie',                             lastname: 'ace',                              age: '24',                         },                     },                 ],             },             {                 data: {                     firstname: 'Sam',                     lastname: 'ace',                      age: '55',                 },                 children: [                     {                         data: {                             firstname: 'Michelle',                             lastname: 'ace',                              age: '20',                         },                     },                     {                         data: {                             firstname: 'Charlie',                             lastname: 'ace',                              age: '24',                         },                     },                 ],             },             {                 data: {                     firstname: 'James',                     lastname: 'ace',                      age: '55',                 },                 children: [                     {                         data: {                             firstname: 'Michelle',                             lastname: 'ace',                              age: '20',                         },                     },                     {                         data: {                             lastname: 'ace',                             firstname: 'Charlie',                              age: '24',                         },                     },                 ],             },         ];     } } 
app.module.ts
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 { NodeService } from './nodeservice'; import { TreeTableModule } from 'primeng/treetable'; import { ButtonModule } from 'primeng/button'; import { InputTextModule } from 'primeng/inputtext';  @NgModule({     imports: [         BrowserModule,         BrowserAnimationsModule,         TreeTableModule,         ButtonModule,         InputTextModule,         HttpClientModule,         FormsModule,     ],     declarations: [AppComponent],     bootstrap: [AppComponent],     providers: [NodeService], })  export class AppModule { } 

Output:

 

Example 2: Below is another example that demonstrates the use of the Angular PrimeNG TreeTable Column Resize. In this example, we are applying Column Resize to the scrollable TreeTable component.

app.component.html
<h2 style="color: green">GeeksforGeeks</h2> <h4>Angular PrimeNG TreeTable Column Resize</h4>  <p-treeTable      [value]="tableData"      [columns]="cols"      [scrollable]="true"      scrollHeight="200px"      [resizableColumns]="true">     <ng-template pTemplate="colgroup" let-columns>         <colgroup>             <col *ngFor="let col of columns" />         </colgroup>     </ng-template>     <ng-template pTemplate="header" let-columns>         <tr>             <th *ngFor="let col of columns"                  ttResizableColumn>                 {{ col.header }}             </th>         </tr>     </ng-template>     <ng-template          pTemplate="body"          let-rowNode          let-rowData="rowData"          let-columns="columns">         <tr>             <td *ngFor="let col of columns; let i = index">                 <p-treeTableToggler                      [rowNode]="rowNode"                      *ngIf="i == 0">                 </p-treeTableToggler>                 {{ rowData[col.field] }}             </td>         </tr>     </ng-template> </p-treeTable> 
app.component.ts
import { Component } from '@angular/core'; import { NodeService } from './nodeservice'; import { TreeNode } from 'primeng/api';  @Component({     selector: 'app-root',     templateUrl: './app.component.html', }) export class AppComponent {     tableData: TreeNode[] = [];     cols: any[] = [];     constructor(private nodeService: NodeService) { }      ngOnInit() {         this.cols = [             {                  field: 'name',                  header: 'Name',                  width: '50%'              },             {                  field: 'age',                  header: 'Age',                  width: '30%'              },         ];         this.tableData = [             {                 data: {                     name: 'David',                     age: '40',                 },                 children: [                     {                         data: {                             name: 'Nathan',                             age: '16',                         },                     },                     {                         data: {                             name: 'Shane',                             age: '14',                         },                     },                 ],             },             {                 data: {                     name: 'Warner',                     age: '55',                 },                 children: [                     {                         data: {                             name: 'Michelle',                             age: '20',                         },                     },                     {                         data: {                             name: 'Charlie',                             age: '24',                         },                     },                 ],             },             {                 data: {                     name: 'Max',                     age: '55',                 },                 children: [                     {                         data: {                             name: 'Michelle',                             age: '20',                         },                     },                     {                         data: {                             name: 'Charlie',                             age: '24',                         },                     },                 ],             },             {                 data: {                     name: 'Willy',                     age: '55',                 },                 children: [                     {                         data: {                             name: 'Michelle',                             age: '20',                         },                     },                     {                         data: {                             name: 'Charlie',                             age: '24',                         },                     },                 ],             },             {                 data: {                     name: 'Miley',                     age: '55',                 },                 children: [                     {                         data: {                             name: 'Michelle',                             age: '20',                         },                     },                     {                         data: {                             name: 'Charlie',                             age: '24',                         },                     },                 ],             },             {                 data: {                     name: 'Sam',                     age: '55',                 },                 children: [                     {                         data: {                             name: 'Michelle',                             age: '20',                         },                     },                     {                         data: {                             name: 'Charlie',                             age: '24',                         },                     },                 ],             },             {                 data: {                     name: 'James',                     age: '55',                 },                 children: [                     {                         data: {                             name: 'Michelle',                             age: '20',                         },                     },                     {                         data: {                             name: 'Charlie',                             age: '24',                         },                     },                 ],             },         ];     } } 
app.module.ts
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 { NodeService } from './nodeservice'; import { TreeTableModule } from 'primeng/treetable';  @NgModule({     imports: [         BrowserModule,         BrowserAnimationsModule,         TreeTableModule,         HttpClientModule,         FormsModule,     ],     declarations: [AppComponent],     bootstrap: [AppComponent],     providers: [NodeService], })  export class AppModule { } 

Output:

 

Reference: https://primefaces.org/primeng/treetable


Next Article
Angular PrimeNG TreeTable - Responsive
author
taran910
Improve
Article Tags :
  • Web Technologies
  • AngularJS
  • Angular-PrimeNG
  • PrimeNG-Data

Similar Reads

  • Angular PrimeNG Table Column Resize
    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 Column Resize in Angular PrimeNG. Angular PrimeNG Tab
    4 min read
  • Angular PrimeNG TreeTable Column Reordering
    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 Column Reordering in Angular PrimeNG. Angular PrimeNG
    6 min read
  • Angular PrimeNG TreeTable Size
    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 Size in Angular PrimeNG. Angular PrimeNG TreeTable Si
    6 min read
  • Angular PrimeNG TreeTable Column Toggle
    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. It provides a lot of templates, components, theme design, an extensive icon library, and much more.
    7 min read
  • Angular PrimeNG TreeTable - Responsive
    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 Column Resize in Angular PrimeNG. Angular PrimeNG Tre
    7 min read
  • Angular PrimeNG TreeTable Column Group
    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 Column Grouping in Angular PrimeNG. Angular PrimeNG T
    6 min read
  • Angular PrimeNG TreeTable Responsive
    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. It provides a lot of templates, components, theme design, an extensive icon library, and much more.
    7 min read
  • Angular PrimeNG TreeTable Column Grouping
    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 Column Grouping in Angular PrimeNG. Angular PrimeNG T
    6 min read
  • Angular PrimeNG Table Column Reordering
    Angular PrimeNG is a UI toolkit to make web applications with Angular. It costing of hundreds of pre-built component that makes it easy for developers to create a beautiful and responsive web solution in less time. In this article, we will see Angular PrimeNG Table Column Reordering. The Table Compo
    5 min read
  • Angular PrimeNG TreeTable Reorder
    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 Column Resize in Angular PrimeNG. Angular PrimeNG Tre
    6 min read
geeksforgeeks-footer-logo
Corporate & Communications Address:
A-143, 7th Floor, Sovereign Corporate Tower, Sector- 136, Noida, Uttar Pradesh (201305)
Registered Address:
K 061, Tower K, Gulshan Vivante Apartment, Sector 137, Noida, Gautam Buddh Nagar, Uttar Pradesh, 201305
GFG App on Play Store GFG App on App Store
Advertise with us
  • Company
  • About Us
  • Legal
  • Privacy Policy
  • In Media
  • Contact Us
  • Advertise with us
  • GFG Corporate Solution
  • Placement Training Program
  • Languages
  • Python
  • Java
  • C++
  • PHP
  • GoLang
  • SQL
  • R Language
  • Android Tutorial
  • Tutorials Archive
  • DSA
  • Data Structures
  • Algorithms
  • DSA for Beginners
  • Basic DSA Problems
  • DSA Roadmap
  • Top 100 DSA Interview Problems
  • DSA Roadmap by Sandeep Jain
  • All Cheat Sheets
  • Data Science & ML
  • Data Science With Python
  • Data Science For Beginner
  • Machine Learning
  • ML Maths
  • Data Visualisation
  • Pandas
  • NumPy
  • NLP
  • Deep Learning
  • Web Technologies
  • HTML
  • CSS
  • JavaScript
  • TypeScript
  • ReactJS
  • NextJS
  • Bootstrap
  • Web Design
  • Python Tutorial
  • Python Programming Examples
  • Python Projects
  • Python Tkinter
  • Python Web Scraping
  • OpenCV Tutorial
  • Python Interview Question
  • Django
  • Computer Science
  • Operating Systems
  • Computer Network
  • Database Management System
  • Software Engineering
  • Digital Logic Design
  • Engineering Maths
  • Software Development
  • Software Testing
  • DevOps
  • Git
  • Linux
  • AWS
  • Docker
  • Kubernetes
  • Azure
  • GCP
  • DevOps Roadmap
  • System Design
  • High Level Design
  • Low Level Design
  • UML Diagrams
  • Interview Guide
  • Design Patterns
  • OOAD
  • System Design Bootcamp
  • Interview Questions
  • Inteview Preparation
  • Competitive Programming
  • Top DS or Algo for CP
  • Company-Wise Recruitment Process
  • Company-Wise Preparation
  • Aptitude Preparation
  • Puzzles
  • School Subjects
  • Mathematics
  • Physics
  • Chemistry
  • Biology
  • Social Science
  • English Grammar
  • Commerce
  • World GK
  • GeeksforGeeks Videos
  • DSA
  • Python
  • Java
  • C++
  • Web Development
  • Data Science
  • CS Subjects
@GeeksforGeeks, Sanchhaya Education Private Limited, All rights reserved
We use cookies to ensure you have the best browsing experience on our website. By using our site, you acknowledge that you have read and understood our Cookie Policy & Privacy Policy
Lightbox
Improvement
Suggest Changes
Help us improve. Share your suggestions to enhance the article. Contribute your expertise and make a difference in the GeeksforGeeks portal.
geeksforgeeks-suggest-icon
Create Improvement
Enhance the article with your expertise. Contribute to the GeeksforGeeks community and help create better learning resources for all.
geeksforgeeks-improvement-icon
Suggest Changes
min 4 words, max Words Limit:1000

Thank You!

Your suggestions are valuable to us.

What kind of Experience do you want to share?

Interview Experiences
Admission Experiences
Career Journeys
Work Experiences
Campus Experiences
Competitive Exam Experiences