将内容范围标头用作表中NgbPagination的collectionSize

我已经基于ng-bootstrap库(https://ng-bootstrap.github.io/#/components/table/examples)中Table组件的分页示例实现了带有分页的表。

<ngb-pagination>元素中,如下定义我的collectionSize

[collectionSize]="collectionSize || async"

这很好用,但是通过这种方式,我必须在API中专门为项目计数创建一个端点。如果我可以仅使用Content-Range标头中的值,而该标头是在检索表中的项目时发送的,则容易得多。

我实现了表格和分页,如下所示:

HTML

    <tbody *ngIf="items | async as rcvItems">
      <tr *ngFor="let item of rcvItems">
        <th scope="col">{{ item.x }}</th>
        <td scope="col">{{ item.y }}</td>
      </tr>
    </tbody>

...

    <ngb-pagination [collectionSize]="collectionSize | async" [(page)]="page" [pageSize]="pageSize" [maxSize]="5"
          [rotate]="true" [ellipses]="false">
    </ngb-pagination>

TS

ngOnInit(){
  // count() gets the total amount of items
  this.collectionSize = this.service.count();
  // list() gets all the items
  this.items = this.service.list(this.pageSize,(this.page - 1) * this.pageSize);
}

服务TS

list(limit,offset): Observable<Item[]> {
  return this.http
    .get(this.baseUrl + '?limit=' + limit + '&offset=' + offset)
    .pipe(
      map((data: any[]) =>
        data.map(item => this.itemAdapter.adapt(item))
      )
    );
}

我试图通过添加list()tap(response => response.headers.get('Content-Range')),方法中获取标头,但这似乎不起作用。 是否可以通过某种方式获取list()方法接收到的项目的响应的标头,并将其用作collectionSize?

谢谢。

a172009839 回答:将内容范围标头用作表中NgbPagination的collectionSize

暂时没有好的解决方案,如果你有好的解决方案,请发邮件至:iooj@foxmail.com
本文链接:https://www.f2er.com/3110575.html

大家都在问