问题
I am using sap.ui.table.Table
. This table has some very good feature but I am having a tough time to figure out how to set the column to auto width. Currently, all the columns are fixed size but I want something if column A value is small, then auto adjust it rather than having fixed size. Same for if the column value is large, then adjust it to show the value.
回答1:
The control sap.ui.table.Column offers a property called autoResizable
by which the user can resize the column width depending on the content of the column's template.
<Column
autoResizable="true"
...
From API Reference:
Enables auto-resizing of the column on double clicking the resize bar. The width is determined on the widest currently displayed content. It does not consider rows which are currently not scrolled into view.
However, as you can see, it requires user interaction. Doing it without user interaction programmatically can be achieved by using the (currently experimental) API autoResizeColumn from sap.ui.table.Table.
myTable.autoResizeColumn(/*ColumnIndex*/); // experimental!
Here is an example of both approaches: https://embed.plnkr.co/NQpkJo/.
来源:https://stackoverflow.com/questions/46922864/how-to-achieve-auto-width-column-in-sap-ui-table-table