Ag grid AG网格不均匀列宽

Ag grid AG网格不均匀列宽,ag-grid,Ag Grid,在使用api.sizeColumnsToFit()时,我正在努力使网格可靠地均匀显示其列宽 我已将网格配置为在父div/浏览器窗口调整大小时调整列的大小: this.gridOptions = <GridOptions>{ onModelUpdated: () => { this.gridOptions.api.sizeColumnsToFit(); }, onGridSizeChanged: () =&g

在使用api.sizeColumnsToFit()时,我正在努力使网格可靠地均匀显示其列宽

我已将网格配置为在父div/浏览器窗口调整大小时调整列的大小:

this.gridOptions = <GridOptions>{
        onModelUpdated: () => {
            this.gridOptions.api.sizeColumnsToFit();
        },
        onGridSizeChanged: () => {
            this.gridOptions.api.sizeColumnsToFit();
        }
    };
this.gridOptions={
onModelUpdated:()=>{
this.gridOptions.api.sizeColumnsToFit();
},
onGridSizeChanged:()=>{
this.gridOptions.api.sizeColumnsToFit();
}
};
这是可行的,但得到的列宽往往是不均匀的。请参见下面第13周的每月第一天和第二天:

我们欢迎您提出任何建议,使其更加可靠。

这里有一个可能的解决方案供您参考。本质上,这里是您可以做的:

var windowWidth = document.querySelector('#myGrid').offsetWidth - 170 - 17,
// calculate the window width minus any columns you don't want to size for
   and a little magic number for the vertical scrollbar (17 was for chrome on mac)

    sizableColumns = gridOptions.columnApi.getColumnState().map(e=>e.colId).filter(e=>e!='athlete'),
// get the colId of only the columns that you want to resize 

    sizableColumnWidth = Math.floor(windowWidth/sizableColumns.length);
// calculate the width of each column by dividing the available width by the number of columns

    sizableColumns.forEach(e=>gridOptions.columnApi.setColumnWidth(e,sizableColumnWidth))
// iterate through the columns you want to resize and set their new column width

然而,我认为你最好考虑一下有多少用户将要调整他们的浏览器窗口。。。不仅如此,还要多次缓慢调整其窗口的大小。查看这些帖子:


这两篇文章都表明大约2%的桌面用户正在调整浏览器的大小。还有一小部分人将多次缓慢调整浏览器的大小。也许您可以简单地告诉他们,我假设您的初始columndef对于每个列都具有相同的宽度,除了“Task”之外,它似乎具有相同的宽度“suppressSizeToFit是否设置为true?类似于。如果运行plnkr并将窗口宽度向右和向后增加几次,然后再次缓慢减小窗口宽度,则“运动员年龄”列的宽度将与所有其他列的宽度不成比例地缩小。这正是我试图避免的。我感谢您周到的回复,Jarod,我将审查您建议的代码。我也同意你的观点,总的来说,也许我的方法不适合使用自动列宽,我应该重新考虑使用固定宽度列的设计目标。我不确定这是否应该标记为已解决或有帮助?