【问题标题】:Pagination issue with ng2-smart-tableng2-smart-table 的分页问题
【发布时间】:2017-08-15 22:17:34
【问题描述】:

我在 Angular 2 应用程序中使用 ng2-smart-table,但其中的分页存在问题。我正在加载一个数据对象数组,它正确显示了前五个(我总共有 20 个),但是表格底部的分页显示 > 箭头之间没有数字,如果我点击右箭头它向我展示了接下来的 15 个。表的设置是:

private tableSettings = {
    columns: {
        id: {
          title: 'ID',
          filter: false
        },
        name: {
          title: 'Name',
          filter: false
        },
    },
    hideSubHeader: true,
    attr: {
        class: 'id-field'
    },
    actions:{
        edit: false
    },
    delete:{
        confirmDelete: true
    },
    pager : {
        display : true,
        perPage:5
    }
}

任何想法为什么它显示 > 而不是 > ? 谢谢!

【问题讨论】:

标签: javascript angular pagination ng2-smart-table


【解决方案1】:

您没有提到您使用的是服务器数据源还是本地数据。假设您使用的是服务器数据源,我猜您没有通过

X-Total-Count: 20

在您的响应标头中,以便客户端知道您总共有多少条记录。

希望对你有帮助。

【讨论】:

    【解决方案2】:

    我遇到过类似的问题,分页根本没有显示。 @Babak 几乎是对的,您需要将 X-Total-Count 添加到您的响应标头中,其中包含总行数,但您还需要通过添加 access-control-expose-headers:X-Total-Count 来公开该标头标题。

    例如对于 C# WebApi:

    var response = new HttpResponseMessage();
    response.Headers.Add("access-control-expose-headers", "X-Total-Count");
    response.Headers.Add("X-Total-Count", "100");
    

    希望这对某人有所帮助。

    【讨论】:

      【解决方案3】:

      您应该将配置对象中的 totalKey 传递给源,如下所示:

      this.source = new ServerDataSource(_http, 
      {
      dataKey: 'data.data',
      endPoint: 'https://myapi/endpoint',
      pagerPageKey: 'page', // this should be page number param name in endpoint (request not response) for example 'page'
      pagerLimitKey: 'pageSize', // this should page size param name in endpoint (request not response)
      totalKey: 'data.meta.total', // this is total records count in response, this will handle pager
      });
      

      【讨论】:

      • 这个服务器数据源和本地数据源有区别吗?
      • 是的,服务器数据是指直接来自服务器的数据,因此预计会发送带有您传递给它的参数的请求,但本地数据意味着您已经拥有数据,因此您想在客户端本地播放它
      猜你喜欢
      • 2017-11-23
      • 2020-07-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-01-08
      • 2020-01-03
      • 1970-01-01
      • 2018-09-21
      相关资源
      最近更新 更多