TurboTable中的延迟加载数据通过请求

时间:2018-07-17 13:35:14

标签: angular lazy-loading primeng primeng-turbotable

我正在使用最新版本的PrimeNG。由于不推荐使用DataTable,因此我不得不使用新的TurboTable来显示搜索结果。

<div *ngIf="result | async as resultlist">
  <p-table #searchResults class="searchResults" [value]="resultlist?.data.content" [paginator]="true" [rows]="20"  (onLazyLoad)="loadLazy($event)" [lazy]="true" [totalRecords]="resultlist?.data.totalElements"  >

  loadLazy(event) {
if(event.first !== undefined && event.rows !== undefined){
  let newPage = (event.first / event.rows) + 1;

  // prevent from sending the same request multiple times
  if(newPage !== this.pageParams.page){
    this.pageParams.page = newPage;
    this.loadSearchResults();

  }
}

}


 loadSearchResults() 
 {
     this.queryParams.page = this.pageParams.page;
     this.queryParams.size = this.pageParams.page_size;

     this.result = this.sucheService.search(this.queryParams);
 }

search(map: { [key: string]: string }): Observable<CollectionContextPartner> {
    const httpParams = Object.keys(map)
    .reduce((param, key) => param.set(key, map[key]), new HttpParams());

    return this.http.get(this.baseUrl + "search", { params: httpParams });
  }

第1页的初始请求(由ngOnInit触发)可以正常工作。当我切换到第二页并触发onLazyLoad事件时,在对页面2进行新的http请求后,整个页面将重新加载。

我只得到以下引用到第一个代码示例的异常:

ERROR Error: ExpressionChangedAfterItHasBeenCheckedError: Expression has changed after it was checked. Previous value: 'ngIf: [object Object]'. Current value: 'ngIf: null'.

0 个答案:

没有答案