【问题标题】:React ag-grid - RefreshInfinitecache() is not workingReact ag-grid - RefreshInfinitecache()不起作用
【发布时间】:2018-09-27 20:34:35
【问题描述】:

我在我的应用程序中使用ag-grid-react。有一个功能,在应用程序中更改数据库路径后,按下刷新按钮后应该加载新数据。

为了实现这一点,我在componentwillreceiveprops 中使用了refreshInfiniteCache,所以当道具发生变化时(使用redux),它应该刷新数据。

请在下面找到代码,

componentWillReceiveProps(nextProps) {
        this.gridApi.refreshInfiniteCache();
        console.log("received");
    }

    onGridReady(params) {
        this.gridApi = params.api;
        this.gridColumnApi = params.columnApi;
        params.api.sizeColumnsToFit();
        window.onresize = () => {
            this.gridApi.sizeColumnsToFit();
        };
        var current = this;
        const updateData = data => {
            data.forEach(function (data, index) {
                data.id = "R" + (index + 1);
            });
            var dataSource = {
                rowCount: null,
                getRows: function (params) {
                    current.setState({
                        paramsparameter: params
                    })
                    var Apiinput = apiinput(params.startRow, params.sortModel, params.filterModel, current.state.restore, current.state.removeallrecords);
                    var res = request('POST', 'http://localhost:4000/paginatedata', { json: Apiinput });
                    var returnfilterdata = JSON.parse(res.getBody('utf8'));
                    var lastRow = -1;
                    if (returnfilterdata.length < 100) {
                        console.log("entered last row");
                        lastRow = returnfilterdata.length;
                    }
                    params.successCallback(returnfilterdata, lastRow);
                }
            };
            params.api.setDatasource(dataSource);
        };
        updateData(this.state.rowData);
    }

但它没有加载新数据。 我不知道我在这里做错了什么。

谢谢 曼格什

【问题讨论】:

    标签: ag-grid


    【解决方案1】:

    您从哪里得知refreshinfinitecache 会更新您的数据?

    来自my post

    refreshInfiniteCache() :将缓存中所有当前加载的块标记为重新加载。如果缓存中有 10 个块,则所有 10 个块都将被标记为重新加载。在加载新数据之前,旧数据将继续显示。

    因此,如果您将通过setRowData(rows) 替换所有网格数据,则可以致电refreshInfiniteCache()

    setRowData(rows) 将新行设置到网格中。

    或者您需要在完成删除请求后update the grid data

    params.api.updateRowData({remove:[...array of data-objects to remove...]});
    

    【讨论】:

      猜你喜欢
      • 2021-02-09
      • 2019-01-21
      • 2021-01-03
      • 1970-01-01
      • 1970-01-01
      • 2019-04-13
      • 2018-09-19
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多