【问题标题】:dataView page not set to 1 after get request获取请求后 dataView 页面未设置为 1
【发布时间】:2020-01-14 08:16:21
【问题描述】:

我有一个带有分页功能的 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 => 
                {

                }));
  }

【问题讨论】:

    标签: angular primeng primeng-datatable data-paging


    【解决方案1】:

    找到了一个基于: 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);
    

    【讨论】:

      猜你喜欢
      • 2018-11-27
      • 2017-07-27
      • 1970-01-01
      • 1970-01-01
      • 2020-07-28
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多