Primefaces DataTable列宽控制或替代解决方案?

时间:2013-10-11 17:47:27

标签: jsf-2 primefaces

我正在使用primefaces数据表和我的代码

<p:dataTable id="dataTableBonusSplit" var="announcements"
    value="#{announcementBean.dataList}" scrollable="true" scrollHeight="550"
     paginator="true" rows="10"
    paginatorPosition="bottom"
    paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
    rowsPerPageTemplate="5,10,15" sortMode="multiple">


    <p:column headerText="Company"
        sortBy="#{announcementBean.cName}" style="width:110px;"
        styleClass="wrap" for="companyName">

        <h:outputText value="#{announcements.companyName}"></h:outputText>
    </p:column>

    <p:column headerText="Type" style="width:110px;"
        styleClass="wrap" sortBy="#{announcements.announcementType}">
        <h:outputText value="#{announcements.announcementType}"></h:outputText>
    </p:column>
    <p:column headerText="Date" style="width:110px;"
        styleClass="wrap" sortBy="#{announcements.announcementDt}">
        <h:outputText value="#{announcements.announcementDt}">
        <f:convertDateTime type="date" pattern="dd/MMM/yyyy" />
        </h:outputText>
    </p:column>
    <p:column headerText="Announcement" style="table-layout: fixed;white-space: normal;"
        sortBy="#{announcements.announcement}"  >
        <h:outputText value="#{announcements.announcement}"></h:outputText>
    </p:column>
</p:dataTable>

你可以看到图片enter image description here,如果你的表格看起来非常糟糕,那就是这个问题。

1 个答案:

答案 0 :(得分:0)

只需将fn:substring()fn:length()结合使用:

<h:outputText value="#{fn:length(announcements.announcement) > 50 ? fn:substring(announcements.announcement,0,50) : announcements.announcement}"  />

如果字符数大于50,那将会缩短输出。