Skip to content Skip to sidebar Skip to footer

Ag-grid Viewport: Cannot Read Property 'bind' Of Undefined

I'm replicating the ag-grid Viewport example putting it in an object representing the table instead of a anonymous function. I cannot understand why it gives me the error in the ti

Solution 1:

(Taken from your question today, similar problems here I think)

You have a timing issue in your plunker - your MockServer is trying to process data before it's available.

You need to do two things to resolve this - the first is to only try set the data source once the data is available in the MockServer:

WatcherTable.prototype.setRowData = function ($http) {
    // set up a mock server - real code will not do this, it will contact your
    // real server to get what it needs
    var mockServer = new MockServer();
    var that = this;
    $http.get('data.json').then(function (response) {
        mockServer.init(response.data);
        var viewportDatasource = new ViewportDatasource(mockServer);
        that.table.api.setViewportDatasource(viewportDatasource);
        // put the 'size cols to fit' into a timeout, so that the scroll is taken into consideration
        setTimeout(function () {
            that.table.api.sizeColumnsToFit();
        }, 100);
    });
}

Secondly, along the same theme, you need to prevent the periodic updates from trying to process data before its ready. Here you can either kick off the periodical updates AFTER the data is available, or more simply add a check before you try use it:

MockServer.prototype.periodicallyUpdateData = function() {
    if(!this.allData) return;

I've forked your plunker (with the above changes) here: https://plnkr.co/edit/cY30aHIPydVOjcihX8Zh?p=preview


Post a Comment for "Ag-grid Viewport: Cannot Read Property 'bind' Of Undefined"