GnanaSagar reddy
GnanaSagar reddy

Reputation: 56

Resize all the columns of multiple instances of ag-grid in a single page

i have a multiple instances of Ag-grid table in a single page, when i resize the browser window the columns are not automatically resizing to the width of table, we are using only one Ag-grid instance to show all the grids in a page but the grid resize(onGridReady event) is working, it working only for last loaded Ag-grid only , please help me in this, thanks

function loadaggrid(id,rowdata,columndata){
    var gridOptions = {
                defaultColDef:{
                    editable: false,
                    enableRowGroup:true,
                    enablePivot:true,
                    enableValue:true,
                    sortable: true,
                    resizable: true,
                    filter: true
                },
                autoGroupColumnDef: {
                    width: 180
                },

                animateRows: true,
                debug: false,
                suppressAggFuncInHeader: true,
                sideBar: {
                    toolPanels: [{
                        id: 'columns',
                        labelDefault: 'Columns',
                        labelKey: 'columns',
                        iconKey: 'columns',
                        toolPanel: 'agColumnsToolPanel',
                        toolPanelParams: {
                            suppressPivots: true,
                            suppressPivotMode: true,
                        }
                    }],
                },
                rowSelection: 'single',
                columnDefs: cols,
                rowData: data,
                floatingFilter:true,
                paginationAutoPageSize:true,
                pagination: true,
                onGridReady: function (params) {
                    window.onresize = () => {
                        setTimeout(function(){
                           params.api.sizeColumnsToFit();
                        },500);
                    }
                },
                onFirstDataRendered(params) {
                    params.api.sizeColumnsToFit();
                }
        }

        new agGrid.Grid(id, gridOptions);
}

Upvotes: 0

Views: 1560

Answers (1)

behruz
behruz

Reputation: 598

you need to implement different onGridReady functions for each grid.

//firstGridOptions:
onGridReady: (event) => {
 console.log('this is for first grid'); 
 this.firstGridApi.sizeColumnsToFit();
},

//secondGridOptions:
onGridReady: (event) => {
 console.log('this is for second grid'); 
 this.secondGridApi.sizeColumnsToFit();
},

Upvotes: 1

Related Questions