在数据列中右对齐单元格内容 [英] Right aligning cell content in a datatable column

查看:114
本文介绍了在数据列中右对齐单元格内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想右对齐一个outputText值(即下面的fee.TableAmount),我想保持该列的标题为中心。我必须传递给outputText下面哪个参数来实现这个?

I want to right align an outputText value (ie. fee.TableAmount below) and I want to keep the header for that column centered. What parameter do I have to pass to outputText below to achieve this?

<h:dataTable>
    ...
    (other columns)
    ...
    <h:column headerClass="columnCenter">
        <f:facet id="header_agency" name="header">
            <h:outputText value="Amount"/>
        </f:facet>
        <h:outputText value="#{fee.tableAmount}">
            <f:convertNumber maxFractionDigits="2" groupingUsed="true"
                currencySymbol="$" type="currency" />
        </h:outputText>
    </h:column>
</h:dataTable>


推荐答案

您可以使用 columnClasses < h:dataTable> 属性来指定同一列的所有单元格上的CSS类。您可以传递一个以逗号分隔的类名称字符串。

You can use the columnClasses attribute of <h:dataTable> to specify CSS classes on all cells of the same column. You can pass a commaseparated string of class names.

<h:dataTable columnClasses="column1,column2,column3">

上面显示< td class =column1> 为第一列,< td class =column2> 为第二列,依此类推。这允许您外部化和规范化样式。

The above renders <td class="column1"> for the first column, <td class="column2"> for the second and so on. This allows you to externalize and normalize the styles.

假设您有4列,而第一,第二和第四列不需要有特殊的样式,只有第三列需要右对齐,然后这样做

Imagine that you have 4 columns and the first, second and fourth column doesn't need to have a special style and that only the third column needs to be right-aligned, then do so

<h:dataTable columnClasses="none,none,right,none">

td.right {
    text-align: right;
}

在语义上更正确,技术上比 float:right;

which is semantically more correct and technically more robust than a float: right;.

这篇关于在数据列中右对齐单元格内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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