首页 > 解决方案 > 如何重置ag-grid无限滚动

问题描述

我目前正在使用 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 重置网格并删除当前数据并再次开始加载数据?以便可以将带有过滤器的新数据加载到网格上。

标签: angularag-grid-angular

解决方案


如果您正在使用:

rowModelType={'serverSide'}

清除数据:

api.purgeServerSideCache(null)

推荐阅读