Ag网格,防止桌子缩放到全宽 [英] Ag grid, prevent table to scale to full width

查看:131
本文介绍了Ag网格,防止桌子缩放到全宽的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个表,即使它的内容较少,它也可以缩放到所有可用宽度。

演示: https://plnkr.co/edit/6L8bTAwkEV6R6Be4M1Qm?p=preview

试图通过给父母一个来解决它width 和ag-grid max-width ,但是如您所见,它没有效果。有谁知道吗?

预先感谢。

I have a table which scales to all available width even though its content is less .
Demo: "https://plnkr.co/edit/6L8bTAwkEV6R6Be4M1Qm?p=preview"
Tried to solve it by giving a parent a width and ag-grid max-width but as you see it has not effect. Has anyone any idea ?
Thanks in advance.

推荐答案

您需要使用 sizeColumnsToFit()方法。


sizeColumnsToFit()获取列以调整大小以适合网格

sizeColumnsToFit() Gets columns to adjust in size to fit the grid horizontally.

官方文档

代码:

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

    this.gridApi.sizeColumnsToFit();
    ....
}

修改了 plnkr示例


更新: sizeColumnsToFit

的说明您需要记住 ag-grid
因此,在这种情况下,要使 sizeColumnsToFit 起作用-应该定义网格并将其分配给 gridOptions 属性。如果需要动态解决方案,请不要忘记先通过 setColumnDefs 通知网格,然后调用 sizeColumnsToFit 方法。

You need to remember the life cycle of the ag-grid. So in this case, to make sizeColumnsToFit works - grid columns should be defined and assigned to gridOptions property. If you need to have a dynamic solution, don't forget to inform your grid via setColumnDefs first, and then call the sizeColumnsToFit method.

这篇关于Ag网格,防止桌子缩放到全宽的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆