我尝试使用此解决方案,但对我而言不起作用,它的正确大小调整了列的高度,但未包装 文本。Ag-Grid-多行文本行
var gridOptions = {
columnDefs: columnDefs,
rowSelection: 'multiple',
enableColResize: true,
enableSorting: true,
enableFilter: true,
enableRangeSelection: true,
suppressRowClickSelection: true,
animateRows: true,
onModelUpdated: modelUpdated,
debug: true,
autoSizeColumns:true,
getRowHeight: function(params) {
// assuming 50 characters per line, working how how many lines we need
return 18 * (Math.floor(params.data.zaglavie.length / 45) + 1);
}
};
function createRowData() {
return gon.books;
}
Run Code Online (Sandbox Code Playgroud)
如果您遵循Docs上的“ Row Height More Complex Example” ,它说您需要添加一些CSS以使单词自动换行。因此,在您的colDef中为您受影响的列(如果我正确遵循的话,为zaglavie)中添加cellStyle: {'white-space': 'normal'}。这是一个演示的plnkr。
啊! resetRowHeights()!!
正如其他人指出的那样,文档允许您使用autoHeight. 然而,当我autoHeight在 my 中实现时,我columnDefs最终得到了太高的行高。为了让它们正确调整大小,您还应该resetRowHeights()通过网格 APIgridReady函数调用。
例子
columnDefs.ts <- 导入 gridOptions
export const columnDefs: Array<any> = [
{
headerName: 'Artifact Name',
field: 'name'
}, {
headerName: 'Artifact Type',
field: 'artifactType',
width: 40,
sortable: true
}, {
headerName: 'Description',
field: 'description',
cellStyle: {'white-space': 'normal'},
autoHeight: true // <- Yay!
}
];
Run Code Online (Sandbox Code Playgroud)
X.component.html
<ag-grid-angular
class="ag-theme-balham"
(gridReady)="onGridReady($event)"
[gridOptions]="gridOptions">
</ag-grid-angular>
Run Code Online (Sandbox Code Playgroud)
X.component.ts
onGridReady(grid) {
grid.api.sizeColumnsToFit();
grid.api.resetRowHeights();
}
Run Code Online (Sandbox Code Playgroud)
编辑
我正在使用 Angular 8。
另一条建议——如果你正在加载行,那么确保你的重置是在承诺返回之后。这可以防止无用的水平滚动条。在此处查看更多相关信息:https : //stackoverflow.com/a/57678686/3769076
| 归档时间: |
|
| 查看次数: |
12307 次 |
| 最近记录: |