gpt4 book ai didi

javascript - 银格 : Autosizing columns at run time not working in chrome/IE 11

转载 作者:行者123 更新时间:2023-12-05 07:17:34 26 4
gpt4 key购买 nike

我在 Angular 框架中有 Ag 网格,在初始加载数据后,我正在动态应用分组(行分组),之后我试图扩展所有组,一旦网格被分组并且行被扩展我想自动调整大小列以避免显示省略号(值...)。

在下面的 plunker 中,我重现了这个问题。我看到在分组后,我使用 hack setTimeout 函数来展开/折叠或自动调整列的大小。

Autosize columns plunker using hack setTimeout, check app.component.ts file

我不想使用这种 hacky 方法,因为我不知道确切的行数(数据),所以在某些情况下 setTimeout 将不起作用。

它在 IE11 中也非常慢,可能需要更多的超时值。

onGridReady(params) {
this.gridApi = params.api;
this.gridColumnApi = params.columnApi;

this.http
.get(
"https://raw.githubusercontent.com/ag-grid/ag-grid/master/packages/ag-grid-docs/src/olympicWinnersSmall.json"
)
.subscribe(data => {
data[0].athlete = 'very very very long text very very very long text very very very long text very very very long text'
this.rowData = data;
this.gridColumnApi.addRowGroupColumns(["sport", "year", "country", "athlete"]);

// This will not work
// this.setDefaultExpanded();

// This will work (hacky solution)
setTimeout(() => {
this.setDefaultExpanded();
}, 1000);

// This will not work
// this.autoSizeAll();

// This will work (hacky solution)
setTimeout(() => {
this.autoSizeAll();
}, 2000);

});
}



setDefaultExpanded() {
this.gridApi.forEachNode(node => {
if (node.group) {
node.expanded = true;
}
});
this.gridApi.onGroupExpandedOrCollapsed();
}


autoSizeAll() {
const allColumnIds = [];
if (this.gridColumnApi) {
this.gridColumnApi.getAllDisplayedColumns().forEach(column => {
allColumnIds.push(column.colId);
});
this.gridColumnApi.autoSizeColumns(allColumnIds);
}

}

感谢任何帮助!!!

谢谢

最佳答案

请使用onFirstDataRendered 事件。一旦数据加载到网格,就会触发此事件。

var gridOptions = {
defaultColDef: {
resizable: true
},
columnDefs: columnDefs,
rowData: null,
onFirstDataRendered: onFirstDataRendered
};

function onFirstDataRendered(params) {
const allColumnIds = [];
if (this.gridColumnApi) {
this.gridColumnApi.getAllDisplayedColumns().forEach(column => {
allColumnIds.push(column.colId);
});
this.gridColumnApi.autoSizeColumns(allColumnIds);
}
}

关于javascript - 银格 : Autosizing columns at run time not working in chrome/IE 11,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/58744535/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com