Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

treetable | deferreddemo, controlled demo, cd onpush update #14866

Merged
merged 1 commit into from
Feb 23, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
46 changes: 24 additions & 22 deletions src/app/showcase/doc/treetable/basicdoc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { ChangeDetectionStrategy, ChangeDetectorRef, Component, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, ChangeDetectorRef, Component } from '@angular/core';
import { TreeNode } from 'primeng/api';
import { Code } from '../../domain/code';
import { NodeService } from '../../service/nodeservice';
Expand All @@ -9,35 +9,37 @@ import { NodeService } from '../../service/nodeservice';
<p>TreeTable requires a collection of <i>TreeNode</i> instances as a <i>value</i> components as children for the representation.</p>
</app-docsectiontext>
<div class="card">
<p-treeTable [value]="files" [scrollable]="true" [tableStyle]="{ 'min-width': '50rem' }">
<ng-template pTemplate="header">
<tr>
<th>Name</th>
<th>Size</th>
<th>Type</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowNode let-rowData="rowData">
<tr [ttRow]="rowNode">
<td>
<p-treeTableToggler [rowNode]="rowNode"></p-treeTableToggler>
{{ rowData.name }}
</td>
<td>{{ rowData.size }}</td>
<td>{{ rowData.type }}</td>
</tr>
</ng-template>
</p-treeTable>
<p-deferred-demo (load)="loadDemoData()">
<p-treeTable [value]="files" [scrollable]="true" [tableStyle]="{ 'min-width': '50rem' }">
<ng-template pTemplate="header">
<tr>
<th>Name</th>
<th>Size</th>
<th>Type</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowNode let-rowData="rowData">
<tr [ttRow]="rowNode">
<td>
<p-treeTableToggler [rowNode]="rowNode"></p-treeTableToggler>
{{ rowData.name }}
</td>
<td>{{ rowData.size }}</td>
<td>{{ rowData.type }}</td>
</tr>
</ng-template>
</p-treeTable>
</p-deferred-demo>
</div>
<app-code [code]="code" selector="tree-table-basic-demo"></app-code>`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class BasicDoc implements OnInit {
export class BasicDoc {
files!: TreeNode[];

constructor(private nodeService: NodeService, private cd: ChangeDetectorRef) {}

ngOnInit() {
loadDemoData() {
this.nodeService.getFilesystem().then((files) => {
this.files = files.slice(0, 5);
this.cd.markForCheck();
Expand Down
85 changes: 44 additions & 41 deletions src/app/showcase/doc/treetable/columngroupdoc.ts
Original file line number Diff line number Diff line change
@@ -1,56 +1,59 @@
import { Component, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { TreeNode } from 'primeng/api';
import { Code } from '../../domain/code';

@Component({
selector: 'column-group-doc',
template: `
<div class="card">
<p-treeTable [value]="sales" [scrollable]="true" [tableStyle]="{ 'min-width': '50rem' }">
<ng-template pTemplate="header">
<tr>
<th rowspan="3">Brand</th>
<th colspan="4">Sale Rate</th>
</tr>
<tr>
<th colspan="2">Sales</th>
<th colspan="2">Profits</th>
</tr>
<tr>
<th>Last Year</th>
<th>This Year</th>
<th>Last Year</th>
<th>This Year</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowNode let-rowData="rowData">
<tr [ttRow]="rowNode">
<td>
<p-treeTableToggler [rowNode]="rowNode"></p-treeTableToggler>
{{ rowData.brand }}
</td>
<td>{{ rowData.lastYearSale }}</td>
<td>{{ rowData.thisYearSale }}</td>
<td>{{ rowData.lastYearProfit }}</td>
<td>{{ rowData.thisYearProfit }}</td>
</tr>
</ng-template>
<ng-template pTemplate="footer">
<tr>
<td colspan="3">Totals</td>
<td>$3,283,772</td>
<td>$2,126,925</td>
</tr>
</ng-template>
</p-treeTable>
<p-deferred-demo (load)="loadDemoData()">
<p-treeTable [value]="sales" [scrollable]="true" [tableStyle]="{ 'min-width': '50rem' }">
<ng-template pTemplate="header">
<tr>
<th rowspan="3">Brand</th>
<th colspan="4">Sale Rate</th>
</tr>
<tr>
<th colspan="2">Sales</th>
<th colspan="2">Profits</th>
</tr>
<tr>
<th>Last Year</th>
<th>This Year</th>
<th>Last Year</th>
<th>This Year</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowNode let-rowData="rowData">
<tr [ttRow]="rowNode">
<td>
<p-treeTableToggler [rowNode]="rowNode"></p-treeTableToggler>
{{ rowData.brand }}
</td>
<td>{{ rowData.lastYearSale }}</td>
<td>{{ rowData.thisYearSale }}</td>
<td>{{ rowData.lastYearProfit }}</td>
<td>{{ rowData.thisYearProfit }}</td>
</tr>
</ng-template>
<ng-template pTemplate="footer">
<tr>
<td colspan="3">Totals</td>
<td>$3,283,772</td>
<td>$2,126,925</td>
</tr>
</ng-template>
</p-treeTable>
</p-deferred-demo>
</div>
<app-code [code]="code" selector="tree-table-column-group-demo"></app-code>
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ColumnGroupDoc implements OnInit {
export class ColumnGroupDoc {
sales!: TreeNode[];

ngOnInit() {
loadDemoData() {
this.sales = [
{
data: { brand: 'Bliss', lastYearSale: '51%', thisYearSale: '40%', lastYearProfit: '$54,406.00', thisYearProfit: '$43,342' },
Expand Down
45 changes: 24 additions & 21 deletions src/app/showcase/doc/treetable/columnresizeexpanddoc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { TreeNode } from 'primeng/api';
import { Code } from '../../domain/code';
import { NodeService } from '../../service/nodeservice';
Expand All @@ -15,35 +15,38 @@ interface Column {
<p>Setting <i>columnResizeMode</i> as <i>expand</i> changes the table width as well.</p>
</app-docsectiontext>
<div class="card">
<p-treeTable [value]="files" [columns]="cols" [resizableColumns]="true" columnResizeMode="expand">
<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 [ttRow]="rowNode">
<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>
<p-deferred-demo (load)="loadDemoData()">
<p-treeTable [value]="files" [columns]="cols" [resizableColumns]="true" columnResizeMode="expand">
<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 [ttRow]="rowNode">
<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>
</p-deferred-demo>
</div>
<app-code [code]="code" selector="tree-table-resize-expand-demo"></app-code>
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ResizeExpandDoc implements OnInit {
export class ResizeExpandDoc {
files!: TreeNode[];

cols!: Column[];

constructor(private nodeService: NodeService) {}

ngOnInit() {
loadDemoData() {
this.nodeService.getFilesystem().then((files) => (this.files = files));
this.cols = [
{ field: 'name', header: 'Name' },
Expand Down
11 changes: 7 additions & 4 deletions src/app/showcase/doc/treetable/columnresizefitdoc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { TreeNode } from 'primeng/api';
import { Code } from '../../domain/code';
import { NodeService } from '../../service/nodeservice';
Expand All @@ -15,6 +15,7 @@ interface Column {
<p>Columns can be resized with drag and drop when <i>resizableColumns</i> is enabled. Default resize mode is <i>fit</i> that does not change the overall table width.</p>
</app-docsectiontext>
<div class="card">
<p-deferred-demo (load)="loadDemoData()">
<p-treeTable [value]="files" [columns]="cols" [resizableColumns]="true" [tableStyle]="{ 'min-width': '50rem' }">
<ng-template pTemplate="header" let-columns>
<tr>
Expand All @@ -32,18 +33,20 @@ interface Column {
</tr>
</ng-template>
</p-treeTable>
</p-deferred-demo>
</div>
<app-code [code]="code" selector="tree-table-resize-fit-demo"></app-code>
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ResizeFitDoc implements OnInit {
export class ResizeFitDoc {
files!: TreeNode[];

cols!: Column[];

constructor(private nodeService: NodeService) {}

ngOnInit() {
loadDemoData() {
this.nodeService.getFilesystem().then((files) => (this.files = files));
this.cols = [
{ field: 'name', header: 'Name' },
Expand Down
55 changes: 29 additions & 26 deletions src/app/showcase/doc/treetable/columnresizescrollabledoc.ts
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
import { Component, OnInit } from '@angular/core';
import { ChangeDetectionStrategy, Component } from '@angular/core';
import { TreeNode } from 'primeng/api';
import { Code } from '../../domain/code';
import { NodeService } from '../../service/nodeservice';
Expand All @@ -15,40 +15,43 @@ interface Column {
<p>To utilize the column resize modes with a <i>scrollable</i> TreeTable, a <i>colgroup</i> template must be defined. The default value of scrollHeight is "flex," it can also be set as a string value.</p>
</app-docsectiontext>
<div class="card">
<p-treeTable [value]="files" [columns]="cols" [resizableColumns]="true" [scrollable]="true" scrollHeight="200px" [tableStyle]="{ 'min-width': '50rem' }">
<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 [ttRow]="rowNode">
<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>
<p-deferred-demo (load)="loadDemoData()">
<p-treeTable [value]="files" [columns]="cols" [resizableColumns]="true" [scrollable]="true" scrollHeight="200px" [tableStyle]="{ 'min-width': '50rem' }">
<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 [ttRow]="rowNode">
<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>
</p-deferred-demo>
</div>
<app-code [code]="code" selector="tree-table-resize-scrollable-demo"></app-code>
`
`,
changeDetection: ChangeDetectionStrategy.OnPush
})
export class ResizeScrollableDoc implements OnInit {
export class ResizeScrollableDoc {
files!: TreeNode[];

cols!: Column[];

constructor(private nodeService: NodeService) {}

ngOnInit() {
loadDemoData() {
this.nodeService.getFilesystem().then((files) => (this.files = files));
this.cols = [
{ field: 'name', header: 'Name' },
Expand Down
Loading
Loading