Bor*_*ris 2 css primefaces jsf-2
我使用Primefaces 3.5与JSF 2,并有一个dataTable:
<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.">
Run Code Online (Sandbox Code Playgroud)
该表包含以下具有大文本描述的列,该列当前被内联截断并显示在链接旁边以弹出具有全文的对话框:
<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>
Run Code Online (Sandbox Code Playgroud)
现在的问题是使用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>
Run Code Online (Sandbox Code Playgroud)
所以任何人都可以告诉我:
截断文本以在dataTable中显示它的最佳方法是什么?
以及如何导出同一个表但已经具有全文值?
纯CSS解决方案在这里:http://ovaraksin.blogspot.com.ar/2012/12/elegant-truncated-text-with-ellipses-in.html
.truncate {
max-width: 160px;
width: 160 px\9;
}
.truncate > div {
width: 160 px\9;
white-space: nowrap;
overflow: hidden;
text-overflow: ellipsis;
-o-text-overflow: ellipsis;
-ms-text-overflow: ellipsis;
display: block;
position: absolute;
}
Run Code Online (Sandbox Code Playgroud)
所以你只需要在页面上设置样式:
<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>
Run Code Online (Sandbox Code Playgroud)
它在流体行为方面并不理想,但它非常简单且有效!