Css 截断p:dataTable中的大文本值并导出带有全文的表
我将Primefaces 3.5与JSF 2一起使用,并有一个数据表:Css 截断p:dataTable中的大文本值并导出带有全文的表,css,jsf-2,primefaces,Css,Jsf 2,Primefaces,我将Primefaces 3.5与JSF 2一起使用,并有一个数据表: <p:dataTable id="dataTable" var="refType" value="#{rtmUiController.listAllRefTypes()}" paginator="true" rows="10" filteredValue="#{rtmUiController.filteredRefTypes}" paginatorTemplate="{C
<p:dataTable id="dataTable" var="refType"
value="#{rtmUiController.listAllRefTypes()}" paginator="true"
rows="10" filteredValue="#{rtmUiController.filteredRefTypes}"
paginatorTemplate="{CurrentPageReport} {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
rowsPerPageTemplate="10,25,50,100" resizableColumns="true"
emptyMessage="No reference type found.">
该表包含以下列,其中包含一个大文本说明,该说明当前被内联截断,并显示在一个链接旁边,以弹出一个包含全文的对话框:
<p:column filterBy="#{refType.description}"
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="Description" />
</f:facet>
<h:outputText value="#{refType.description.substring(30)}" />
<p:commandLink id="descriptionLink" value="... (full text)"
oncomplete="descriptionDialog.show()"
update=":tabView:form1:descriptionPanel"
rendered="#{not empty refType.description}">
<f:setPropertyActionListener value="#{refType.description}"
target="#{flash.description}" />
</p:commandLink>
</p:column>
<p:dialog widgetVar="descriptionDialog" resizable="false"
header="Reference Type Description">
<p:panelGrid id="descriptionPanel" columns="1">
<h:outputText id="description" value="#{flash.description}" />
</p:panelGrid>
</p:dialog>
现在的问题是使用showcase中的标准primefaces dataExporter功能将具有全文值的表导出为PDF或任何其他格式,因为它只导出表的确切内容:
<h:panelGrid>
<p:panel header="Export Table Data">
<h:commandLink>
<p:graphicImage id="pdfImage" value="/resources/images/pdf.png" />
<p:dataExporter type="pdf" target="dataTable" fileName="refTypes"
showEffect="fade" hideEffect="fade" />
<p:tooltip for="pdfImage" value="Export table data to PDF file"
showEffect="fade" hideEffect="fade" />
</h:commandLink>
</p:panel>
</h:panelGrid>
那么,有谁能告诉我:
尝试设置
description
字段的样式,这样可以对其内容进行换行:
。文本换行{
空白:正常;
单词包装:打断单词;
单词break:打破一切;
}
纯CSS解决方案如下:
因此,您只需在页面上设置样式:
<p:column headerText="Description" sortBy="#{user.description}" styleClass="truncate">
<h:outputText id="desc" value="#{user.description}"/>
<pe:tooltip for="desc" value="#{user.description}"/>
</p:column>
它不是理想的流体行为,但它是相当简单,它的作品 我正在使用Primefaces 5.3,而我的
使用的内联解决方案:
<p:column headerText="Category" style="text-overflow: ellipsis; white-space: nowrap;">
<p:outputLabel value="#{p.category.name}" style="display: inline;"/>
</p:column>
我将答案移植到Primefaces 6.0,并编写了以下代码片段
.truncate {
max-width: 120px;
}
.truncate > span:nth-child(2):not(.ui-icon) {
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
display: block;
}
CSS选择器更复杂,因为我们希望避免为列的排序图标设置样式。相应的Primefaces示例
<p:column headerText="Description" sortBy="#{user.description}" styleClass="truncate">
<h:outputText id="desc" value="#{user.description}"/>
<p:tooltip for="desc" value="#{user.description}"/>
</p:column>
Hello@BalusC,你可以给我一些建议吗?谢谢,但要求表格中显示截断的文本,能够弹出全文并导出全文。对于前两个,你可以使用view对象并使用Java剪切文本,然后,当用户单击单元格时,用全文显示属性。对于最后一个问题,我不确定您是否可以使用primefaces exporter。据我所知,PF exporter导出表中已经可见的内容。你应该为此生成自己的导出器。这会为我生成两倍于导出文件字段中的值。
<p:column headerText="Description" sortBy="#{user.description}" styleClass="truncate">
<h:outputText id="desc" value="#{user.description}"/>
<p:tooltip for="desc" value="#{user.description}"/>
</p:column>