Ag grid, prevent table to scale to full width

久未见 提交于 2019-12-24 19:00:24

问题


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.


回答1:


You need to use sizeColumnsToFit() method.

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

Official doc

Code:

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

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

Modified your plnkr sample

Update: explanation of 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.



来源:https://stackoverflow.com/questions/52344268/ag-grid-prevent-table-to-scale-to-full-width

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!