Angular PrimeNG表风格
Angular PrimeNG是一个开源框架,拥有丰富的原生Angular UI组件,可用于出色的造型,这个框架用于制作响应式网站,非常容易。本文将告诉我们如何在Angular PrimeNG中使用TreeTable Column Resize。
Angular PrimeNG Table Style是用来根据条件对表格单元格和行进行样式设计的。这使得表格组件更具有交互性和用户友好性。
语法:
// In app.component.ts
.classname{
// Styles
}
// In app.component.html
<tr [ngClass]="{'className': condition}">
HTML
创建Angular应用程序和模块安装。
第1步:使用以下命令创建一个Angular应用程序。
ng new appname
JavaScript
第2步:创建你的项目文件夹即appname后,使用以下命令移动到它。
cd appname
JavaScript
第3步在你给定的目录中安装PrimeNG。
npm install primeng --save
npm install primeicons --save
JavaScript
项目结构:它将看起来像如下。
Project Structure
例子1:下面是一个简单的例子,演示Angular PrimeNG Table Style的使用。
<div class="page-content" style="height: calc(100vh - 149px)">
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Table Style</h4>
<p-table
[value]="tableData"
[scrollable]="true"
scrollHeight="flex">
<ng-template pTemplate="header">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
</ng-template>
<ng-template
pTemplate="body"
let-rowData="rowData"
let-people
sortMode="multiple">
<tr [ngClass]="{ row: people.firstname == 'David' }">
<td>
{{ people.firstname }}
</td>
<td>
{{ people.lastname }}
</td>
<td>
{{ people.age }}
</td>
</tr>
</ng-template>
</p-table>
</div>
HTML
import { Component } from '@angular/core';
interface People {
firstname?: string;
lastname?: string;
age?: string;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styles: [
`
.row {
background-color: blue !important;
color: #ffffff !important;
}
`
],
})
export class AppComponent {
tableData: People[] = [];
cols: any[] = [];
constructor() { }
ngOnInit() {
this.cols = [
{ field: 'firstname', header: 'First Name' },
{ field: 'lastname', header: 'Last Name' },
{ field: 'age', header: 'Age' },
];
this.tableData = [
{
firstname: 'David',
lastname: 'ace',
age: '40',
},
{
firstname: 'AJne',
lastname: 'west',
age: '40',
},
{
firstname: 'Mak',
lastname: 'Lame',
age: '40',
},
{
firstname: 'Peter',
lastname: 'raw',
age: '40',
},
{
firstname: 'Kane',
lastname: 'James',
age: '40',
},
];
}
}
JavaScript
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { TableModule } from 'primeng/table';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
TableModule,
FormsModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
JavaScript
输出:
例子2:下面是另一个演示Angular PrimeNG Table风格使用的例子。
<div class="page-content" style="height: calc(100vh - 149px)">
<h2 style="color: green">GeeksforGeeks</h2>
<h4>Angular PrimeNG Table Style</h4>
<p-table
[columns]="cols"
[value]="tableData"
[scrollable]="true"
scrollHeight="flex">
<ng-template pTemplate="header">
<tr>
<th>First Name</th>
<th>Last Name</th>
<th>Age</th>
</tr>
</ng-template>
<ng-template
pTemplate="body"
let-people
sortMode="multiple">
<tr>
<td [ngClass]="{ row: true }">
{{ people.firstname }}
</td>
<td>
{{ people.lastname }}
</td>
<td>
{{ people.age }}
</td>
</tr>
</ng-template>
</p-table>
</div>
HTML
import { Component } from '@angular/core';
interface People {
firstname?: string;
lastname?: string;
age?: string;
}
@Component({
selector: 'app-root',
templateUrl: './app.component.html',
styles: [
`
.row {
background-color: blue !important;
color: #ffffff !important;
}
.cell {
background-color: black !important;
}
`,
],
})
export class AppComponent {
tableData: People[] = [];
cols: any[] = [];
constructor() { }
ngOnInit() {
this.cols = [
{ field: 'firstname', header: 'First Name' },
{ field: 'lastname', header: 'Last Name' },
{ field: 'age', header: 'Age' },
];
this.tableData = [
{
firstname: 'David',
lastname: 'ace',
age: '40',
},
{
firstname: 'AJne',
lastname: 'west',
age: '40',
},
{
firstname: 'Mak',
lastname: 'Lame',
age: '40',
},
{
firstname: 'Peter',
lastname: 'raw',
age: '40',
},
{
firstname: 'Kane',
lastname: 'James',
age: '40',
},
];
}
}
JavaScript
import { NgModule } from '@angular/core';
import { BrowserModule } from '@angular/platform-browser';
import { FormsModule } from '@angular/forms';
import { BrowserAnimationsModule }
from '@angular/platform-browser/animations';
import { AppComponent } from './app.component';
import { TableModule } from 'primeng/table';
@NgModule({
imports: [
BrowserModule,
BrowserAnimationsModule,
TableModule,
FormsModule,
],
declarations: [AppComponent],
bootstrap: [AppComponent],
})
export class AppModule { }
JavaScript
输出: