我正在使用带有延迟加载选项的 PrimeNG TurboTable 来显示来自数据库的数据。这很完美。现在,我需要向发送到服务器的请求添加一些过滤器。怎么做 ?
这是有效的代码:
<p-table [columns]="cols" [value]="persons" [paginator]="true" [rows]="10" [lazy]="true" (onLazyLoad)="loadPersonsLazy($event)"
[totalRecords]="totalRecords" [loading]="loading">
<ng-template pTemplate="header" let-columns>
<tr>
<th *ngFor="let col of columns">
{{col.header}}
</th>
</tr>
</ng-template>
<ng-template pTemplate="body" let-rowData let-columns="columns">
<tr>
<td *ngFor="let col of columns">
{{rowData[col.field]}}
</td>
</tr>
</ng-template>
</p-table>
组件 .ts 代码:
import { Component, OnInit } from '@angular/core';
import{IPerson} from '../iperson'
import{PrimengServiceService} from '../primeng-service.service'
import {LazyLoadEvent} from 'primeng/api';
import {FilterMetadata} from 'primeng/api';
@Component({
selector: 'app-person',
templateUrl: './person.component.html',
styleUrls: ['./person.component.css']
})
export class PersonComponent implements OnInit {
constructor(private _primengService: PrimengServiceService) { }
persons:IPerson[] =[];
cols: any[];
totalRecords:number=100;
loading: boolean;
ngOnInit() {
this.cols = [
{ field: 'FirstName', header: 'First Name' },
{ field: 'LastName', header: 'Last Name' },
{ field: 'EMail', header: 'EMail' },
{ field: 'Phone', header: 'Phone' }
];
}
loadPersonsLazy(event: LazyLoadEvent) {
this.loading = true;
this._primengService.getPersonList(event.first,event.rows).subscribe(res=>this.persons=res,
error => {
this.loading = false;
console.log(`Error - getPersonList method: ${error}`);
},
() => {
this.loading = false;
console.log(`Info - getPersonList method succeeded. Results: ${JSON.stringify(this.persons)}`);
})
}
}