-
Notifications
You must be signed in to change notification settings - Fork 4.7k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
1 parent
fc8747b
commit be077eb
Showing
4 changed files
with
215 additions
and
1 deletion.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,80 @@ | ||
import { ChangeDetectorRef, Component, OnInit } from '@angular/core'; | ||
import { TreeNode } from 'primeng/api'; | ||
import { Code } from '../../domain/code'; | ||
import { NodeService } from '../../service/nodeservice'; | ||
|
||
@Component({ | ||
selector: 'virtual-scroll-doc', | ||
template: ` | ||
<app-docsectiontext> | ||
<p>VirtualScroller is a performance-approach to handle huge data efficiently. Setting <i>virtualScroll</i> property as true and providing a <i>virtualScrollItemSize</i> in pixels would be enough to enable this functionality.</p> | ||
</app-docsectiontext> | ||
<div class="card flex justify-content-center"> | ||
<p-tree class="w-full md:w-30rem" scrollHeight="250px" [virtualScroll]="true" [virtualScrollItemSize]="46" [value]="files"></p-tree> | ||
</div> | ||
<app-code [code]="code" selector="tree-virtual-scroll-demo"></app-code> | ||
` | ||
}) | ||
export class VirtualScrollDoc implements OnInit { | ||
loading: boolean = false; | ||
|
||
files!: TreeNode[]; | ||
|
||
constructor(private nodeService: NodeService, private cd: ChangeDetectorRef) {} | ||
|
||
ngOnInit() { | ||
this.nodeService.getFiles().then((data) => { | ||
this.files = this.duplicateData(data, 50); | ||
this.cd.markForCheck(); | ||
}); | ||
} | ||
|
||
duplicateData(data: TreeNode[], count: number): TreeNode[] { | ||
let duplicatedData: TreeNode[] = []; | ||
for (let i = 0; i < count; i++) { | ||
duplicatedData = [...duplicatedData, ...data.map((item) => ({ ...item }))]; | ||
} | ||
return duplicatedData; | ||
} | ||
|
||
code: Code = { | ||
basic: `<p-tree class="w-full md:w-30rem" scrollHeight="250px" [virtualScroll]="true" [virtualScrollItemSize]="46" [value]="files"></p-tree>`, | ||
|
||
html: ` | ||
<div class="card flex justify-content-center"> | ||
<p-tree class="w-full md:w-30rem" scrollHeight="250px" [virtualScroll]="true" [virtualScrollItemSize]="46" [value]="files"></p-tree> | ||
</div>`, | ||
|
||
typescript: ` | ||
import { Component, OnInit } from '@angular/core'; | ||
import { TreeNode } from 'primeng/api'; | ||
@Component({ | ||
selector: 'tree-template-demo', | ||
templateUrl: './tree-template-demo.html' | ||
}) | ||
export class TreeTemplateDemo implements OnInit { | ||
loading: boolean = false; | ||
files!: TreeNode[]; | ||
constructor(private nodeService: NodeService, private cd: ChangeDetectorRef) {} | ||
ngOnInit() { | ||
this.nodeService.getFiles().then((data) => { | ||
this.files = this.duplicateData(data, 50); | ||
this.cd.markForCheck(); | ||
}); | ||
} | ||
duplicateData(data: TreeNode[], count: number): TreeNode[] { | ||
let duplicatedData: TreeNode[] = []; | ||
for (let i = 0; i < count; i++) { | ||
duplicatedData = [...duplicatedData, ...data.map((item) => ({ ...item }))]; | ||
} | ||
return duplicatedData; | ||
} | ||
}` | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,114 @@ | ||
import { ChangeDetectorRef, Component, OnInit } from '@angular/core'; | ||
import { TreeNode } from 'primeng/api'; | ||
import { Code } from '../../domain/code'; | ||
import { NodeService } from '../../service/nodeservice'; | ||
|
||
@Component({ | ||
selector: 'lazy-virtual-scroll-doc', | ||
template: ` | ||
<app-docsectiontext> | ||
<p>VirtualScroller is a performance-approach to handle huge data efficiently. Setting <i>virtualScroll</i> property as true and providing a <i>virtualScrollItemSize</i> in pixels would be enough to enable this functionality.</p> | ||
</app-docsectiontext> | ||
<div class="card flex justify-content-center"> | ||
<p-tree class="w-full md:w-30rem" scrollHeight="250px" [virtualScroll]="true" [lazy]="true" [virtualScrollItemSize]="46" [value]="files" (onNodeExpand)="nodeExpand($event)" [loading]="loading"></p-tree> | ||
</div> | ||
<app-code [code]="code" selector="tree-virtual-scroll-lazy-demo"></app-code> | ||
` | ||
}) | ||
export class LazyVirtualScrollDoc implements OnInit { | ||
loading: boolean = false; | ||
|
||
files!: TreeNode[]; | ||
|
||
virtualFiles!: TreeNode[]; | ||
|
||
constructor(private nodeService: NodeService, private cd: ChangeDetectorRef) {} | ||
|
||
ngOnInit() { | ||
this.loading = true; | ||
setTimeout(() => { | ||
this.nodeService.getLazyFiles().then((files) => (this.files = this.duplicateData(files, 50))); | ||
this.loading = false; | ||
this.cd.markForCheck(); | ||
}, 1000); | ||
} | ||
|
||
duplicateData(data: TreeNode[], count: number): TreeNode[] { | ||
let duplicatedData: TreeNode[] = []; | ||
for (let i = 0; i < count; i++) { | ||
duplicatedData = [...duplicatedData, ...data.map((item) => ({ ...item }))]; | ||
} | ||
return duplicatedData; | ||
} | ||
|
||
nodeExpand(event: any) { | ||
if (event.node) { | ||
this.loading = true; | ||
setTimeout(() => { | ||
this.nodeService.getLazyFiles().then((nodes) => { | ||
event.node.children = nodes; | ||
this.files = [...this.files, event.node.children]; | ||
}); | ||
this.loading = false; | ||
this.cd.markForCheck(); | ||
}, 200); | ||
} | ||
} | ||
|
||
code: Code = { | ||
basic: `<p-tree class="w-full md:w-30rem" scrollHeight="250px" [virtualScroll]="true" [lazy]="true" [virtualScrollItemSize]="46" [value]="files" (onNodeExpand)="nodeExpand($event)" [loading]="loading"></p-tree>`, | ||
|
||
html: `<div class="card flex justify-content-center"> | ||
<p-tree class="w-full md:w-30rem" scrollHeight="250px" [virtualScroll]="true" [lazy]="true" [virtualScrollItemSize]="46" [value]="files" (onNodeExpand)="nodeExpand($event)" [loading]="loading"></p-tree> | ||
</div>`, | ||
|
||
typescript: ` | ||
import { Component, OnInit } from '@angular/core'; | ||
import { TreeNode } from 'primeng/api'; | ||
@Component({ | ||
selector: 'tree-template-demo', | ||
templateUrl: './tree-template-demo.html' | ||
}) | ||
export class TreeTemplateDemo implements OnInit { | ||
loading: boolean = false; | ||
files!: TreeNode[]; | ||
virtualFiles!: TreeNode[]; | ||
constructor(private nodeService: NodeService, private cd: ChangeDetectorRef) {} | ||
ngOnInit() { | ||
this.loading = true; | ||
setTimeout(() => { | ||
this.nodeService.getLazyFiles().then((files) => (this.files = this.duplicateData(files, 50))); | ||
this.loading = false; | ||
this.cd.markForCheck(); | ||
}, 1000); | ||
} | ||
duplicateData(data: TreeNode[], count: number): TreeNode[] { | ||
let duplicatedData: TreeNode[] = []; | ||
for (let i = 0; i < count; i++) { | ||
duplicatedData = [...duplicatedData, ...data.map((item) => ({ ...item }))]; | ||
} | ||
return duplicatedData; | ||
} | ||
nodeExpand(event: any) { | ||
if (event.node) { | ||
this.loading = true; | ||
setTimeout(() => { | ||
this.nodeService.getLazyFiles().then((nodes) => { | ||
event.node.children = nodes; | ||
this.files = [...this.files, event.node.children]; | ||
}); | ||
this.loading = false; | ||
this.cd.markForCheck(); | ||
}, 200); | ||
} | ||
} | ||
}` | ||
}; | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters