简体   繁体   English

如何在PrimeFaces 3.0的ap:dataTable中设置ap:column的宽度?

[英]How to set width of a p:column in a p:dataTable in PrimeFaces 3.0?

I'm using PrimeFaces 3.0-M3 and I have a <p:dataTable> with two columns in it. 我正在使用PrimeFaces 3.0-M3,并且有一个<p:dataTable>其中有两列。 I want the first column to be fixed at a width of 20px. 我希望将第一列固定为20px的宽度。 The other column can use whatever space is left over. 另一列可以使用剩余的任何空间。

Here are screenshots of what I'm currently getting: 以下是我目前所获得的屏幕截图:

屏幕截图1

屏幕截图2

The first <p:column> seems to be ignoring the style setting that should have limited the width. 第一个<p:column>似乎忽略了应该限制宽度的style设置。 It is sized way too big for the tiny coloured square that is the only content inside it and then the other column is pushed too far to the right. 它的大小太大了,无法容纳其中最小的彩色正方形,然后将另一列推到右边。

Here is more of my Facelet code: 这是我的Facelet代码的更多内容:

<p:dataTable
        id="dataTableExpressions"
        value="#{catconBean.userDefinedExpressionDataModel}"
        var="currentRow"
        emptyMessage="!! EMPTY TABLE MESSAGE !!"
        selection="#{catconBean.userDefinedExpressionToEdit}"
        selectionMode="single">
    <p:ajax 
            event="rowSelect" 
            listener="#{catconBean.onUserDefinedExpressionRowSelect}"
            update=":toolbarForm:catconToolbar" />
    <p:ajax 
            event="rowUnselect" 
            listener="#{catconBean.onUserDefinedExpressionRowUnselect}"
            update=":toolbarForm:catconToolbar" />

    <p:column id="paletteColor" style="width:20px;">
        <h:panelGroup 
                layout="block"
                rendered="#{not empty currentRow.paletteColor}"
                style="width:16px;height:16px;border:thin;border-style:solid;border-color:black;background-color:##{currentRow.paletteColor.RGB};" />
        <h:panelGroup 
                layout="block"
                rendered="#{empty currentRow.paletteColor}"
                style="width:16px;height:16px;border:thin;border-style:dashed;border-color:red;background-color:white;text-align:center;">
            <h:outputText value="?" style="color:red;font-weight:bold;" />
        </h:panelGroup>
    </p:column>

    <p:column id="name">
        <f:facet name="header">
            <h:outputText value="#{bundle.catcon_label_CategoryName}" />
        </f:facet>
        <h:outputText 
            value="#{currentRow.name}"
            style="#{not currentRow.definitionComplete ? 'color:red;' : ''}" />
    </p:column>
</p:dataTable>

Can anyone tell me how to modify my Facelet code to make the first column have a fixed width of 20px? 谁能告诉我如何修改Facelet代码以使第一列的固定宽度为20px?

In PrimeFaces 3.0, that style get applied on the generated inner <div> of the table cell, not on the <td> as you (and I) would expect. 在PrimeFaces 3.0中,该样式将应用于表单元格的生成的内部<div> ,而不是您(和我)期望的应用于<td> The following example should work out for you: 以下示例将为您解决:

<p:dataTable styleClass="myTable">

with

.myTable td:nth-child(1) {
    width: 20px;
}

In PrimeFaces 3.5 and above, it should work exactly the way you coded and expected. 在PrimeFaces 3.5及更高版本中,它应完全按照您编码和预期的方式工作。

这对我有用

<p:column headerText="name" style="width:20px;"/>

For some reason, this was not working 由于某种原因,这不起作用

<p:column headerText="" width="25px" sortBy="#{row.key}">

But this worked: 但这有效:

<p:column headerText="" width="25" sortBy="#{row.key}">

我不知道您使用的是哪种浏览器,但是根据w3schools.com,nth-child和nth-last-child现在可以在MSIE 8上运行。我不知道9。http://www.w3schools .com / cssref / pr_border-style.asp将为您提供更多信息。

你能试一下吗

<p:column width="20">

我刚刚做了以下工作(在V 3.5中),它像一个魅力一样起作用:

<p:column headerText="name" width="20px"/>

Addition to @BalusC 's answer. 除了@BalusC的答案。 You also need to set width of headers. 您还需要设置标题的宽度。 In my case, below css can only apply to my table's column width. 就我而言,css以下仅适用于表的列宽。

.myTable td:nth-child(1),.myTable th:nth-child(1) {
   width: 20px;
}

内联样式在任何情况下都可以使用

  <p-column field="Quantity" header="Qté" [style]="{'width':'48px'}">

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM