AG-Grid - How to increase row height dynamically?

三世轮回 提交于 2019-12-24 10:23:27

问题


This question is related to Ag-Grid row height on Angular 4 Project. Please see the below scenario:-

I have an Ag-Gird having 3 columns respectively:-

  1. Id (resizable column from UI)
  2. Name (resizable column from UI)
  3. Address (resizable column from UI)

I do not have any limitations( like the limited number of character or words is allowed) on Address column. Users can type any number of characters or words they want to.

Issues:-

  1. How to increase the row height, when Address column width is completely filled-up with words or when users press Enter or Shift + Enter?
  2. How to adjust height automatically when users resize the Address column?

Please help me with these issues.

Thanks


回答1:


There are multiple things to be taken care.

Have a look at the updated Stackblitz

  1. Have cellClass: "cell-wrap-text" attribute in the ColDef for Address column and have the appropriate CSS
  2. Handle columnResized event so that this.gridApi.resetRowHeights() can be called to adjust the height of the rows whenever the column is resized
  3. Also handle cellEditingStopped event, so that when the data for the column is updated, the row height also gets updated accordingly.

    onColumnResized() {
       this.gridApi.resetRowHeights();
    }
    onCellEditingStopped() {
      this.onColumnResized();
    }
    
  4. Provide autoHeight: true property in the defaultColDef

    defaultColDef = { autoHeight: true };


Update:

provide cellEditor: 'agLargeTextCellEditor' if you want to have textarea like control for this field.

Check this StackBlitz



来源:https://stackoverflow.com/questions/55263232/ag-grid-how-to-increase-row-height-dynamically

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