具有无限滚动的AG网格分页

时间:2018-02-22 15:34:48

标签: angular ag-grid ag-grid-ng2

我在角度4上实施ag-grid并且在服务器端分页时遇到问题。

在使用无限滚动实现分页时,有没有办法转到网格就绪事件的特定页面?

1 个答案:

答案 0 :(得分:1)

当你说具有无限滚动的特定页面时,我假设你想要达到特定的滚动位置。

让我们说,您从服务器获取20条记录(您getRows方法也提取相同数量的记录),并且您希望在加载网格时50th进行记录。

按照以下步骤操作。

// #1  initialize grid with empty array, getRows will fetch the records
let dataSource = {
  rowCount: null,
  getRows: (params: IGetRowsParams) => this.getRows(params, [])
};
this.gridApi.setDatasource(dataSource);


// #2.
private getRows(params: IGetRowsParams, data: any) {
    this.yourSvc.getRows(serverParams, params.startRow)
        .subscribe((result: any[]) => {

             params.successCallback(result, null);

             // #3. keep a flag just to make sure its done for the first time only
             if(this.isFirstTime) {
                this.gridApi.ensureColumnVisible(0);
                this.gridApi.ensureIndexVisible(50);
                this.gridApi.setFocusedCell(50, 0, null);

                this.isFirstLoad = false;
             }
        });
}
相关问题