问题描述
我正在使用 sap.ui.table.Table
.这个表格有一些非常好的功能,但我很难弄清楚如何将列设置为自动宽度.
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.
目前,所有列都是固定大小,但如果 列 A 值很小,我想要一些东西,然后自动调整它而不是固定大小.如果列值较大,则相同,然后调整以显示值.
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.
我看到了另一个问题 sap.ui.table.列出如何优化列宽,但答案是获得固定大小的列布局,而不是自动宽度.
I saw the other question sap.ui.table.Table how to optimize column widths but the answers there are to get column layout with fixed sizes, not auto width.
推荐答案
控件 sap.ui.table.Column
提供了一个名为 autoResizable
的属性,用户可以通过该属性根据内容调整列宽列的模板.
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"
...
来自 API 参考:
在双击调整大小栏时启用列的自动调整大小.宽度由最宽的当前显示内容决定.它不考虑当前未滚动到视图中的行.
但是,如您所见,它需要用户交互.可以通过使用(目前处于实验阶段的)API autoResizeColumn
来自 sap.ui.table.Table.
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!
以下是两种方法的示例:https://embed.plnkr.co/NQpkJo/.
Here is an example of both approaches: https://embed.plnkr.co/NQpkJo/.
这篇关于如何在 sap.ui.table.Table 中实现自动宽度列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!