我使用了 ag-grid ng2 并尝试应用 sizeColumnsToFit。例如:如果有 4 列,那么它应该自动调整大小并适合网格的宽度。gridOptions.api.sizeColumnsToFit() 不工作。
var gridOptions = {
columnDefs: columnDefs,
rowData: null,
enableColResize: true
};
this.columnDefs = [
{headerName: "Age", field: "age", width: 90, minWidth: 50, maxWidth: 100},
{headerName: "Country", field: "country", width: 120},
{headerName: "Year", field: "year", width: 90},
{headerName: "Date", field: "date", width: 110}
];
gridOptions.api.sizeColumnsToFit();