angular - Angular 5中的分页索引号

标签 angular angular5 angular2-forms angular-material2

我正在处理一个在 Angular 5 中使用 WordPress API 的项目。我使用了 Material 网格以及过滤和分页。我面临索引问题,比如我总共有 100 个条目,但我想在单页中显示 50 个。当我单击下一步时,接下来的 50 个条目显示在网格中,但索引号再次从 1 到 50 而不是 51 到 100 开始。 如何获取最后一页索引号并与下一页连接。

Filtering

<div class="example-header">
  <mat-form-field>
    <input matInput type="text" placeholder="Component" aria-label="Number" [matAutocomplete]="autocom" #component>
    <mat-autocomplete #autocom="matAutocomplete" (optionSelected)="dropDown($event.option.value,region.value,sector.value,stats.value,page)">
      <mat-option [value]="" style="font-size: 14px;">
        ALL
      </mat-option>
      <mat-option *ngFor="let option of options" [value]="option" style="font-size: 14px;">
        {{ option }}
      </mat-option>
    </mat-autocomplete>
  </mat-form-field>

  <mat-form-field>
    <input matInput type="text" placeholder="Region" aria-label="Number" [matAutocomplete]="autoreg" #region>
    <mat-autocomplete #autoreg="matAutocomplete" (optionSelected)="dropDown(component.value,$event.option.value,sector.value,stats.value,page)">
      <mat-option [value]="" style="font-size: 14px;">
        ALL
      </mat-option>
      <mat-option *ngFor="let option of regions" [value]="option" style="font-size: 14px;">
        {{ option }}
      </mat-option>
    </mat-autocomplete>
  </mat-form-field>
<div>

Pagination

<mat-paginator #pagination [length]="length" [pageSize]="pageSize" [pageSizeOptions]="pageSizeOptions" (page)="pageEvent = dropDown(component.value,region.value,sector.value,stats.value,$event)"
    #page>
  </mat-paginator>

component.ts

pageEvent: PageEvent;

  totalPageSize = 1;
  length: number;
  pageIndex: number = 1;
  pageSize: number = 100;
  pageSizeOptions: number[] = [10, 25, 50, 100];

loadData() {
    this.spinnerService.show();
    this.subscription = this.grantsearchservice.getStarterApi(this.component, this.region, this.sector, this.stats, this.pageIndex, this.pageSize)
      .subscribe(
        (grantsearch: any) => {
          this.grantsearchs = grantsearch.body;
          this.dataSource = new MatTableDataSource(this.grantsearchs);
          this.totalPageSize = grantsearch.headers.get('X-WP-TotalPages');
          this.setPagination(grantsearch.headers.get('x-wp-total'), this.pageIndex, this.pageSize);
          this.spinnerService.hide();
        }
      );
  }

最佳答案

我必须假设你有一些喜欢

   <ng-container matColumnDef="position">
      <th mat-header-cell *matHeaderCellDef> No. </th>
      <td mat-cell *matCellDef="let element"> {{element.position}} </td>
    </ng-container>

只需将 {{element.position}} 更改为 {{element.position+pageSize*(pageIndex-1)}}

   <ng-container matColumnDef="position">
      <th mat-header-cell *matHeaderCellDef> No. </th>
      <td mat-cell *matCellDef="let element"> {{element.position+pageSize*(pageIndex-1)}}

关于angular - Angular 5中的分页索引号,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51056077/

相关文章:

node.js - 如何解决这种情况 Error ERESOLVE could not resolve

css - 为什么我不能用 Angular5 显示 Font-Awesome

javascript - Angular : ngFor data items and display custom message if empty

javascript - 如何使用单独的添加按钮在 IONIC2/Angular2 表单中添加嵌套字段

javascript - 在 RC6 中升级到 @angular/forms

angular - Angular2 是否有相当于 $sceDelegateProvider.resourceUrlWhitelist 和 $sceDelegateProvider.resourceUrlBlacklist 的东西?

javascript - 扩展复选框的检查区域

Angular @ViewChild 错误 'Cannot read property nativeElement of undefined"

unit-testing - 如何在 Angular2 中对 FormControl 进行单元测试

angular - 测试 Angular 库,同时测试库组件和示例应用程序