如何重置ag-grid无限滚动

时间:2019-03-01 22:19:04

标签: angular ag-grid-angular

我当前正在使用rowModelType:'infinite'实现ag-grid,并且当用户向下滚动到列表时加载数据。用户将不得不一次过滤100万条记录,而我们每个用户都存储着外部过滤器。

这些外部过滤器被发送到后端,以仅获取用户需要查看的记录。当用户选择这些过滤器时,我需要通过重置页数并返回以获取过滤的记录来向网格中重新加载新数据,目前,我正在HTTP请求中传递过滤器。

我当前的代码如下所示。

var datasource = {
    rowCount: null,
    getRows: function (params) {
        console.log("asking for " + params.startRow + " to " + params.endRow);
        that.service.loadDataViaSubscription(that.getActiveFilter())
        .map((response: Response) => {
            console.log("Mapping the data from api.");
            return <any>response.json();
        })
        .subscribe(
        data => {
            setTimeout(function () {
                var rowsThisPage = data[0];
                that.currentRecordCount = params.endRow;
                if (params.startRow === 0) {
                    that.currentRecordCount = rowsThisPage.length < 100 ? 100 : rowsThisPage.length;
                }
                else {
                        that.currentRecordCount = params.startRow + rowsThisPage.length;
                }
                params.successCallback(rowsThisPage, that.currentRecordCount);
                that.agGridOptions.api.hideOverlay();
            }, 500);
        });
    }
};

我如何告诉ag-grid重置网格并删除当前数据并再次开始加载数据?这样可以将带有过滤器的新数据加载到网格中。

1 个答案:

答案 0 :(得分:1)

如果您使用的是:

rowModelType={'serverSide'}

清除数据:

api.purgeServerSideCache(null)