0

我有一个 p-dataView (PrimNG) 与分页工作正常,除了一些分页问题。如果我分页到 1 以外的页面,然后调用其余 api 并接收数据,则 dataView 仍然在同一页面上,而不是将其设置为第 1 页。在我看来,这不是所需的行为。我试过使用 [first] 属性,但它什么也没做。这是我的代码:

    <p-button label="getdata" (onClick)="loadData()"></p-button>

    <p-dataView [value]="datafromDB" [rows]="pageSize" [totalRecords]='totalRecords' 
        [paginator]="true" paginatorPosition="bottom" [sortField]="sortColumn" [sortOrder]="sortOrder" [loadingIcon]="loadingIcon" [loading]="loading" [emptyMessage]="">
        <p-header>
            <div >
                headers
            </div>
        </p-header>
        <ng-template let-result pTemplate="listItem">
          <div class="list-item">
            <div>
              content
            </div>
          </div>
        </ng-template>
      </p-dataView>

组件代码:

   loadData()
  {

    this.setReportRequest();
    this.executeReport();
  }

  setReportRequest()
  {
    initiate get request 
  }


  executeReport()
  {

    this.loading = true;
    this.subscriptions.push(this.srv.getdata(request).subscribe(result => 
      {
        this.loading = false;
        this.totalRecords = result.data;
        this.totalPages = result.TotalPages;
        this.datafromDB = this.makeSomeMapping(result.recordset);
      }, error => 
                {

                }));
  }
4

1 回答 1

0

找到了一个解决方案: Get current page and move to specific page in NgPrime datatable

我设置了对dataView的模板引用,然后使用了dataView的paginate()函数。请参阅我的固定(简化)代码:

<p-dataView #DV ...

在组件中:

@ViewChild('DV') dataView: DataView;

执行报告(){

this.loading = true;
this.subscriptions.push(this.srv.getdata(request).subscribe(result => 
  {
    this.loading = false;
    this.totalRecords = result.data;
    this.totalPages = result.TotalPages;
    this.datafromDB = this.makeSomeMapping(result.recordset);
    let paging = { first: 0, rows: <page size - number of rocords>};
    this.dataView.paginate(paging);
于 2019-09-15T08:41:40.700 回答