如何将自定义内容(如换行符)放在p:column标头中 [英] How to put custom content like a linebreak inside p:column header
问题描述
在我的应用程序中,我有以下< p:dataTable>
:
In my application, I have the following <p:dataTable>
:
第二列的标题占用太多空间。因此,我想在 Number of
& 会话
,还可以垂直对齐表格的标题。我试图减小列的宽度,但是并没有自动导致换行。
The 2nd column's header costs too much spaces. Hence, I'd like to put a linebreak between Number of
& Sessions
and also vertically align the headers of the table. I tried to reduce the width of the column but it didn't automatically result in a linebreak.
此外,由于标题名称是从 l10n.properties
文件中检索的,因此我也尝试将其设置为 / n会话数
,但 / n
打印为普通字符串。
Besides, since the header name is retrieved from the l10n.properties
file, I also tried to set it as Number of /n Sessions
but /n
was printed out as a normal string.
更新:我还尝试将属性设置为< br />会话
。但是,在生成的HTML代码中,< br />
消失了,该表看起来与上面完全相同。
UPDATE: I also tried to set the property as Number of <br/> Sessions
. However, in the HTML code generated, <br/>
disappeared and the table looks exactly the same as above.
如果您能给我一个建议,我将不胜感激。
I'd be very grateful if you could give me an advice.
最诚挚的问候,
推荐答案
首先,您需要从列中删除 headerText
属性,然后在其中添加页眉构面:
First of all, you need to remove the headerText
attribute from the column and add a header facet inside it:
/* no_of_sessions = Number of Sessions */
<p:column ... >
<f:facet name="header">
<h:outputText value="#{l10n.no_of_sessions}"
escape="false" style="white-space:pre-line;" />
</f:facet>
...
</p:column>
escape = false
是相关的因此html被转义了,那么您可以在其中放置任何内容。如果您只想为内容设置样式,则不需要
The escape="false"
is relevant so html is escaped, then you can put anything you want in there. If you just want to style content, this is not needed
这篇关于如何将自定义内容(如换行符)放在p:column标头中的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!