我使用的是 PrimeFaces 3.0-M3,我有一个 <p:dataTable>
其中有两列。我希望第一列的宽度固定为 20px。另一列可以使用剩余的任何空间。
以下是我目前得到的截图:
第一个<p:column>
似乎忽略了 style
应该限制宽度的设置。它的大小对于其中唯一内容的彩色小方 block 来说太大了,然后另一列被推到右边太远。
这是我的更多 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>
谁能告诉我如何修改我的 Facelet 代码使第一列的宽度固定为 20 像素?
最佳答案
在 PrimeFaces 3.0 中,该样式应用于生成的内部 <div>
表格单元格的,不在 <td>
上正如你(和我)所期望的那样。以下示例应该适合您:
<p:dataTable styleClass="myTable">
与
.myTable td:nth-child(1) {
width: 20px;
}
在 PrimeFaces 3.5 及更高版本中,它应该完全按照您编码和预期的方式工作。
关于css - 如何设置 p :column in a p:dataTable in PrimeFaces 3. 0 的宽度?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7434203/