首页 > 解决方案 > how to avoid whitespace on right side if columns are less in Ag grid

问题描述

The answer might be sizeTofit . But When I have to resize the column then that whitespace is coming on the right side of the grid.

So I need to do the last column of the grid to occupy the grid fully if columns are less (Or if I remove come column)otherwise it will take the column width provided by the property to Ag grid

This is the image I am getting now

This is the image I am getting now

like this I want

like this I want

标签: reactjsag-grid

解决方案


如果它的大小不是您想要的,那么您可以编写一个函数并手动进行计算。

设置列的宽度,最后为您的 ag 网格设置新的列定义;

var tableWidth = sth;
var totalWidth = 0;
for(var i = 0; i<columnDefs.length; i++) {
    totalWidth += columnDefs[i].width;
    if((i == columnDefs.length - 1) && (totalWidth < tableWidth)) {
        columnDefs[i] += tableWidth - totalWidth;
    }
}
api.setColumnDefs(columnDefs);

推荐阅读