Home > Blockchain >  correct implementation of datasource pagination
correct implementation of datasource pagination

Time:01-31

So at first page it shows the corrrect display

enter image description here


But when I click next page it is displaying , it it displaying 21-20 of , which is wrong.

enter image description here

enter image description here

#html code that uses the component add passes the prefix text and suffix text

<app-table-paginator-text [dataSource]="dataSource" [prefixText]="'Showing'" [suffixText]="'results'"></app-table-paginator-text>  

#data source html code

<div id="table-paginator-text"  *ngIf="dataSource.paginator !== undefined">
  {{prefixText}} {{(dataSource.paginator.pageIndex === 0)? 1: (dataSource.paginator.pageSize * dataSource.paginator.pageIndex)   1 }} - {{this.dataSource.connect().value.length}} of {{dataSource.data.length}} {{suffixText}}      
</div>    

CodePudding user response:

In your data source code, you are correctly offsetting the left-hand number by the pageSize, but the right-hand side is simply the length of the current set. You need to add the offset there, too. I think the following should do it:

(dataSource.paginator.pageSize * dataSource.paginator.pageIndex)   this.dataSource.connect().value.length

CodePudding user response:

Try:

<div id="table-paginator-text"  *ngIf="dataSource.paginator !== undefined">
  {{prefixText}} {{(dataSource.paginator.pageIndex === 0)? 1: (dataSource.paginator.pageSize * dataSource.paginator.pageIndex   1)}} - {{dataSource.paginator.pageSize * dataSource.paginator.pageIndex   this.dataSource.connect().value.length}} of {{dataSource.data.length}} {{suffixText}}      
</div>
  •  Tags:  
  • Related