0
votes

I am using ag-grid-react in my application. There is one feature, after changing the database path in the application, and after pressing the refresh button it should load new data.

To achieve this I am using refreshInfiniteCache in componentwillreceiveprops, so when props will change( using redux), it should refresh data.

please find below code,

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);
    }

But it is not loading new data. I do not know what am I doing wrong here.

Thanks Mangesh

1

1 Answers

0
votes

From where you get that refreshinfinitecache will update your data?

From my post:

refreshInfiniteCache() : Marks all the currently loaded blocks in the cache for reload. If you have 10 blocks in the cache, all 10 will be marked for reloading. The old data will continue to be displayed until the new data is loaded.

So you can call refreshInfiniteCache() if you will replace all grid data via setRowData(rows)

setRowData(rows) Set new rows into the grid.

or you need to update the grid data after completing a delete request.

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