【问题标题】:Centering output text in a primefaces datatable column在 primefaces 数据表列中居中输出文本
【发布时间】:2018-09-11 16:29:18
【问题描述】:

我已经搜索了几个小时的资源,试图找到一个可行的解决方案来解决我认为的一个简单问题:如何在 primefaces 数据表的各个列中居中输出文本?

我看到的每一个地方都说用<div> 标签包围列,这对我来说真的很奇怪而且效率低下。很多地方都说要使用style="center",这行不通。即使在primefaces.org extensions showcase 给出的示例也表明这不起作用,他们有:

 <p:column filterBy="#{message.country}">  
      <f:facet name="header">  
         <h:outputText value="Country" />  
      </f:facet>  
         <h:outputText value="#{message.country}" style="center"/>  
 </p:column>  

但是,国家/地区的数据是左对齐的。

为了使列中的文本居中:

<p:column headerText="Last Name">
    <h:outputText value="#{item.lastName}" />
</p:column>

这是:

<p:column headerText="Last Name">
    <div align="center">
        <h:outputText value="#{item.lastName}" />
    </div>
</p:column>

唯一的办法?

【问题讨论】:

    标签: css jsf primefaces


    【解决方案1】:

    您可以为 p:column 元素定义 styleClass 属性,然后使用 css 设置正确的样式。

    <p:column headerText="Last Name" styleClass="centeredColumnContent">
        <h:outputText value="#{item.lastName}" />
    </p:column>
    

    在你的 CSS 中

    td.centeredColumnContent{
        text-align: center;
    }
    

    【讨论】:

    猜你喜欢
    • 2013-10-26
    • 2020-02-02
    • 2018-10-21
    • 1970-01-01
    • 2019-02-19
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2016-02-05
    相关资源
    最近更新 更多