p:dataTable与p:具有自定义宽度的列 [英] p:dataTable with p:columns with custom widths

查看:72
本文介绍了p:dataTable与p:具有自定义宽度的列的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个通过p:columns标记包含动态列的数据表,并且希望为每个列指定不同的宽度.

I have a Datatable with dynamic columns via the p:columns tag and want to specify a different width for each column.

我的代码如下

<p:dataTable id="scheduleDataTable" value="#{scheduleMB.scheduledRecords}" var="sched" rows="10">
        <p:columns value="#{scheduleMB.columns}" var="column" columnIndexVar="colIndex" styleClass="day-column">  
            <f:facet name="header">
                #{column.header}
            </f:facet>

            #{sched[column.property]}
        </p:columns>  
    </p:dataTable>

在css文件中我有宽度

in the css file I have the width

.ui-state-default .day-column{
 width: 150px !important;
}

我什至尝试了styld ="width:150px;"它们都不起作用,这些列将使用默认值绘制.

i even tried styld="width:150px;" both of them doesn't work, the columns are drawn with default values.

但是我想要不同的列宽,我该怎么做. 我试过像在styleClass ="col1,col2"中指定多个css,在方面方面指定

but i want different column widths, how do i do it. I tried like specifying multiple css in styleClass="col1,col2", specifying in facet like

<f:facet name="style">
    #{column.size}
</f:facet>

推荐答案

设置PrimeFaces DataTable的列宽的官方方法是使用无单位整数定义column元素的width属性.像这样:

The official way to set the column width for the PrimeFaces DataTable is to define the width attribute of the column element using a unitless integer. Like this:

<p:column width="70">
    <h:outputText value="#{element.prop}" />
</p:column>

您可以使用EL来让控制器定义宽度.

You can use EL to let the controller define the width.

此建议适用于PF的3.3和3.4版本,对于较旧的版本可能有所不同.在最近的几个版本更新中,详细信息已更改了几次,因此您可能还想咨询迁移指南

The advice applies to the 3.3 and 3.4 versions of PF and may be different for older ones. The details have changed several times over the last few version updates, so you may also wwant to consult the migration guide

这篇关于p:dataTable与p:具有自定义宽度的列的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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