如何在 sap.ui.table.Table 中实现自动宽度列? [英] How to achieve auto width Column in sap.ui.table.Table?

查看:50
本文介绍了如何在 sap.ui.table.Table 中实现自动宽度列?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用 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 参考:

在双击调整大小栏时启用列的自动调整大小.宽度由最宽的当前显示内容决定.它不考虑当前未滚动到视图中的行.

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.

但是,如您所见,它需要用户交互.可以通过使用(目前处于实验阶段的)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 中实现自动宽度列?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆