AG Grid valueGetter + Pagination

时间:2018-01-29 15:06:49

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

我使用ag网格(angular2)渲染表格,并使用valueGetter功能将行数据渲染为ui。

我想在我的ui上添加onscroll分页,但找不到使用数据源的方法。

`gridOptions.api.setDatasource(ds);` 

如何在这里合作valueGetter和分页?

valueGetter code

this.gridData  = {cols:["col1", "col2"], rows:[["data1","data2"],
["data3","data4"]]};
this.columnDefs = [];
this.rowData = this.gridData.rows;
for (var i in this.gridData.cols){
  var scopeOutCurrIndex = i => (params) => params.data[i]
  this.columnDefs.push({
    headerName: this.gridData.cols[i],
    valueGetter: scopeOutCurrIndex(i)
  })
}

1 个答案:

答案 0 :(得分:0)

这很简单,可以使用相同的实现来实现此目的:

 var dataSource = {
        data: gData,
        rowCount: null,
        getRows: function (params) {
            console.log("asking for " + params.startRow + " to " + params.endRow);
            var rowsThisPage = this.data.slice(params.startRow, params.endRow);
            var lastRow = -1;
            if (this.data.length <= params.endRow) {
                lastRow = this.data.length;
            }
            params.successCallback(rowsThisPage, lastRow);
        }
    };

    this.gridApi.setDatasource(dataSource);