我正在尝试为 primefaces 数据表定义固定的列宽。显然,设置宽度不起作用,因此创建了一个 CSS 文件,但这也不起作用。任何提示或解决方案将不胜感激。谢谢!
<p:dataTable id="messagesTableId" emptyMessage="#{messageBundle.tableNoResultsFound}"
value="#{messageSearchBean.lazyModel}" var="message"
styleClass="messageOccurenceResult-table">
<f:facet name="header">
<h:outputText value="#{messageBundle['global.search.results']}"/>
</f:facet>
<p:column headerText="#{messageBundle['message.send.date']}"
styleClass="messageOccurenceResult-table" >
<h:outputText value="#{message.sendDate}"/>
</p:column>
<p:column headerText="#{messageBundle['message.cc.email']}" style="width:*;
word-wrap:break-word;">
<h:outputText value="#{message.ccEmailIds}" />
</p:column>
<p:column headerText="#{messageBundle['message.messages.sent']}"
style="word-wrap:break-word;">
<h:outputText value="#{fn:length(message.messageOccurrence)}"/>
</p:column>
</p:dataTable>
CSS文件如下
.messageOccurenceResult-table td:nth-child(1) {
width:75px !important;
}
.messageOccurenceResult-table td:nth-child(2) {
width:125px !important;
}
.messageOccurenceResult-table td:nth-child(3){
width:75px !important;
}
内部结构如萤火虫所示
<table role="grid">
<thead>
<tr>
<tr>
<tr role="row">
<th id="messageDisplayForm:messagesTableId:j_idt86"
class="ui-state-default ui- sortable-column ui-state-active" style="width:10%;"
role="columnheader">
<div class="ui-dt-c">
<span class="ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s ui-icon-triangle-1-
s"></span>
<span>Date Sent</span>
</div>
</th>
<th id="messageDisplayForm:messagesTableId:j_idt88"
class="ui-state-default ui-sortable-column" style="width:10%;" role="columnheader">
<div class="ui-dt-c">
<span class="ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s"></span>
<span>Subject</span>
</div>
</th>
<th id="messageDisplayForm:messagesTableId:j_idt90" class="ui-state-default"
style="width:20%;" role="columnheader">
<div class="ui-dt-c">
<span>Message Category</span>
</div>
</th>
<th id="messageDisplayForm:messagesTableId:j_idt92" class="ui-state-default ui-sortable- column" style="word-wrap:break-word;" role="columnheader">
<div class="ui-dt-c">
<span class="ui-sortable-column-icon ui-icon ui-icon-carat-2-n-s"></span>
<span>Sender Email</span>
</div>
</th>
<th id="messageDisplayForm:messagesTableId:j_idt98"
class="ui-state-default" style="width:50px;" role="columnheader">
<div class="ui-dt-c">
<span>Messages Sent</span>
</div>
</th>
</tr>
</thead>
<tfoot>
<tbody id="messageDisplayForm:messagesTableId_data"
class="ui-datatable-data ui-widget-content">
</table>