-
Notifications
You must be signed in to change notification settings - Fork 4.6k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Fixed #9717 - New Lazy Table Demo with Remote Source
- Loading branch information
1 parent
3909c9c
commit 66e91e0
Showing
5 changed files
with
108 additions
and
56 deletions.
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 |
---|---|---|
@@ -1,53 +1,51 @@ | ||
import { Component, OnInit } from '@angular/core'; | ||
import { Customer } from '../../domain/customer'; | ||
import { Customer, Representative } from '../../domain/customer'; | ||
import { CustomerService } from '../../service/customerservice'; | ||
import { LazyLoadEvent } from 'primeng/api'; | ||
import { FilterMetadata } from 'primeng/api'; | ||
|
||
@Component({ | ||
templateUrl: './tablelazydemo.html' | ||
}) | ||
export class TableLazyDemo implements OnInit { | ||
|
||
datasource: Customer[]; | ||
|
||
customers: Customer[]; | ||
|
||
totalRecords: number; | ||
|
||
cols: any[]; | ||
|
||
loading: boolean; | ||
|
||
representatives: Representative[]; | ||
|
||
constructor(private customerService: CustomerService) { } | ||
|
||
ngOnInit() { | ||
//datasource imitation | ||
this.customerService.getCustomersLarge().then(data => { | ||
this.datasource = data; | ||
this.totalRecords = data.length; | ||
}); | ||
this.representatives = [ | ||
{name: "Amy Elsner", image: 'amyelsner.png'}, | ||
{name: "Anna Fali", image: 'annafali.png'}, | ||
{name: "Asiya Javayant", image: 'asiyajavayant.png'}, | ||
{name: "Bernardo Dominic", image: 'bernardodominic.png'}, | ||
{name: "Elwin Sharvill", image: 'elwinsharvill.png'}, | ||
{name: "Ioni Bowcher", image: 'ionibowcher.png'}, | ||
{name: "Ivan Magalhaes",image: 'ivanmagalhaes.png'}, | ||
{name: "Onyama Limba", image: 'onyamalimba.png'}, | ||
{name: "Stephen Shaw", image: 'stephenshaw.png'}, | ||
{name: "Xuxue Feng", image: 'xuxuefeng.png'} | ||
]; | ||
|
||
this.loading = true; | ||
} | ||
|
||
loadCustomers(event: LazyLoadEvent) { | ||
this.loading = true; | ||
|
||
//in a real application, make a remote request to load data using state metadata from event | ||
//event.first = First row offset | ||
//event.rows = Number of rows per page | ||
//event.sortField = Field name to sort with | ||
//event.sortOrder = Sort order as number, 1 for asc and -1 for dec | ||
//filters: FilterMetadata object having field as key and filter value, filter matchMode as value | ||
|
||
//imitate db connection over a network | ||
setTimeout(() => { | ||
if (this.datasource) { | ||
this.customers = this.datasource.slice(event.first, (event.first + event.rows)); | ||
this.customerService.getCustomers({lazyEvent: JSON.stringify(event)}).then(res => { | ||
this.customers = res.customers; | ||
this.totalRecords = res.totalRecords; | ||
this.loading = false; | ||
} | ||
}) | ||
}, 1000); | ||
} | ||
|
||
} |
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 |
---|---|---|
@@ -1,3 +1,4 @@ | ||
export const environment = { | ||
production: true | ||
production: true, | ||
apiUrl: 'https://www.primefaces.org/data/customers' | ||
}; |
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