#StackBounty: #jquery #ag-grid How to fire Ag-Grid Resize inside jquery

Bounty: 200

I’m using jQuery. Outside of the document.ready function, I’m setting up my ag-grid.

const columnDefs = [
    { headerName: 'ID', field: 'id' },
    { headerName: 'Name', field: 'name' },
    { headerName: 'Age', field: 'age' }
];

const gridOptions = {
    defaultColDef: {
        resizable: true
    },
    columnDefs: columnDefs,
    enableSorting: true,
    enableFilter: true,
    onFirstDataRendered: onFirstDataRendered,
};

document.addEventListener('DOMContentLoaded', function () {
    var gridDiv = document.querySelector('#myGrid');
    new agGrid.Grid(gridDiv, gridOptions);
});

function onFirstDataRendered(params) {
    params.api.sizeColumnsToFit();
}

The documentation said to use OnFirstDataRendered for resizing, but I was getting a warning that it is invalidGridOptions. I ignored the warning and proceeded. The grid rows are set after the API call via

gridOptions.api.setRowData(gridData)

, but the resize method is not called; therefore, my columns are not resized.
I have tried using onRowDataUpdated instead, but I get the same result, the function is not hit and it doesn’t size the columns.


Get this bounty!!!

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.