简体   繁体   English

调整单个页面中多个 ag-grid 实例的所有列的大小

[英]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我在单个页面中有多个 Ag-grid 表实例,当我调整浏览器 window 的大小时,列不会自动调整为表的宽度,我们只使用一个 Ag-grid 实例来显示页面中的所有网格但是网格调整大小(onGridReady 事件)正在工作,它仅适用于最后加载的 Ag-grid,请帮助我,谢谢

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

you need to implement different onGridReady functions for each grid.您需要为每个网格实现不同的 onGridReady 函数。

//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();
},

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM