Ag Grid服务器端分页

Ste*_*eve 2 ag-grid ag-grid-ng2 angular

我正在尝试在ag-Grid中实现服务器端分页,每次单击下一个/上一个按钮时,我都会进行SOAP调用。我已经用特定的页码实现了该功能,因此我可以检索行数据并将其传递给Grid。有什么好的例子吗?提前致谢。

Ren*_*abu 17

经过整天的农业网格数据库研究,我终于找到了解决方案。

首先让我们在GridOptions中包含以下选项;

GridOptions

  gridOptions: GridOptions = {
    pagination: true,
    rowModelType: 'infinite',
    cacheBlockSize: 20, // you can have your custom page size
    paginationPageSize: 20 //pagesize
  };
Run Code Online (Sandbox Code Playgroud)

GridReady回调

网格准备好后,设置数据源,例如

onGridReady(params: any) {
    this.gridApi = params.api;
    this.gridApi.setDatasource(this.dataSource) // replace dataSource with your datasource
  } 
Run Code Online (Sandbox Code Playgroud)

数据源对象:当您转到下一页时,ag-grid将调用dataSource对象,从而获取数据。

getRows函数为您提供特定页面的开始结束索引。

params.successCallback:它有两个参数,第一个与page有关的数据,第二个是totalRecords。Ag-grid使用第二个参数来确定总页数。

dataSource: IDatasource = {
    getRows: (params: IGetRowsParams) => {

      // Use startRow and endRow for sending pagination to Backend
      // params.startRow : Start Page
      // params.endRow : End Page

      //replace this.apiService with your Backend Call that returns an Observable
      this.apiService().subscribe(response => {

        params.successCallback(
          response.data, response.totalRecords
        );

      })
    }
  }
Run Code Online (Sandbox Code Playgroud)

示例API服务:这是我使用过的示例API服务

apiService() {
    return this.httpclient.get('https://raw.githubusercontent.com/ag-grid/ag-grid/master/packages/ag-grid-docs/src/olympicWinners.json')
  }
Run Code Online (Sandbox Code Playgroud)

我已将此示例上传到GitHub上

  • 谢谢..它对我有用..被困在同一天多了。rowModelType: 'infinite' 对我来说缺少一些东西。 (2认同)

Dee*_*i-l 3

ag-grid(版本 10 及以上)不支持服务器端分页。如果要实现服务器端分页,可以使用无限滚动的分页https://www.ag-grid.com/javascript-grid-infinite-scrolling/#pagination&gsc.tab=0