0

I'm having a p-dataView (PrimNG) with paging that working fine except for some paging issue. If I page to a page other than 1 and then make a call to the rest api and recieve the data, the dataView is still on the same page instead of setting it to page 1. Seems to me this is not the desired behaviour. I've tried using the [first] property but it did nothing. Here is my code:

    <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>

The component code:

   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 => 
                {

                }));
  }
Guy E
  • 1,775
  • 2
  • 27
  • 55

1 Answers1

0

Found a solution based on: Get current page and move to specific page in NgPrime datatable

I set template reference to the dataView, and then used paginate() function of the dataView. See my fixed (simplified) code:

<p-dataView #DV ...

In the component:

@ViewChild('DV') dataView: DataView;

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);
    let paging = { first: 0, rows: <page size - number of rocords>};
    this.dataView.paginate(paging);
Guy E
  • 1,775
  • 2
  • 27
  • 55