【问题标题】:The resizableColumns of Primefaces data table doesn't work properlyPrimefaces 数据表的 resizableColumns 不能正常工作
【发布时间】:2015-10-23 09:09:24
【问题描述】:

我有一个 JSF 页面,其中有一个包含许多列的表。当我尝试使列可调整大小时,结果很奇怪,并且对于所有浏览器都不相同。

对于 FireFox,第一列(演示代码中的“ID”)可以正常工作。当您尝试将第二列(“书名”)的右边界向左推时,其下一列将在两侧展开。其余的列只有有限的空间可以放大。

对于 Chrome,情况更为严峻。第一列不能放大。当您尝试扩大其余列时,整个表格的宽度实际上正在缩小。

Microsoft Edge 的行为与 FireFox 大致相同。

我正在使用 Primefaces 5.2 和 JSF 2.2 (JavaEE 7) 并使用 GlassFish 4.1 作为服务器。开发环境是带有 Bundled Maven 3.0.5 的 NetBeans 8.0.2。

我包含JSF和CSS的演示代码,有谁知道解决方案,请帮助。提前致谢。

JSF 页面:

    <h:head>
    <title>Data Table Format</title>                
    <h:outputStylesheet name="css/datatable-format.css"/>          
</h:head>
<h:body>
    <h:form>
        <p:dataTable styleClass="ui-datatable-hor-scroll" var="book" value="#{publishedBookView.books}" id="viewDataTable" paginator="true" rows="20"
                     paginatorTemplate="{Calendar} {RowsPerPageDropdown} {FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink} {Exporters}"
                     rowsPerPageTemplate="10,20,50,100" resizableColumns="true" liveResize="true" paginatorPosition="top">
            <f:facet name="{Calendar}">
                <p:outputLabel class="header-calendar">From Date</p:outputLabel>
                <p:calendar class="header-calendar" id="fromDate" value="#{book.publishDate}" pattern="dd MMM yyyy"  readonlyInput="true">
                  <p:ajax event="dateSelect" update="viewDataTable" />
                </p:calendar>
                <p:outputLabel class="header-calendar">To Date</p:outputLabel>
                <p:calendar class="header-calendar" id="toDate" value="#{book.publishDate}" pattern="dd MMM yyyy" readonlyInput="true" >
                  <p:ajax event="dateSelect" update="viewDataTable"/>
                </p:calendar>  
            </f:facet>
            <f:facet name="{Exporters}">
              <h:commandLink>
                <p:graphicImage name="/img/excel.png" styleClass="exporter-button"/>
                <p:dataExporter type="xls" target="viewDataTable" fileName="records" />
              </h:commandLink>
              <h:commandLink>
                <p:graphicImage name="/img/csv.png" styleClass="exporter-button"/>
                <p:dataExporter type="csv" target="viewDataTable" fileName="records" />
              </h:commandLink>
            </f:facet>
            <p:column headerText="ID" class="book-id-format" sortBy="#{book.bookId}" filterBy="#{book.bookId}" filterMatchMode="contains">
                <h:outputText value="#{book.bookId}"/>
            </p:column>
            <p:column headerText="BOOK Name" class="book-name-format">
                <h:outputText value="#{book.bookName}" />
            </p:column>
            <p:column headerText="Published Date 01" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>                
            <p:column headerText="Published Date 02" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>  
            <p:column headerText="Published Date 03" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>                
            <p:column headerText="Published Date 04" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>  
            <p:column headerText="Published Date 05" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>                
            <p:column headerText="Published Date 06" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>  
            <p:column headerText="Published Date 07" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>                
            <p:column headerText="Published Date 08" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>
            <p:column headerText="Published Date 09" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>                
            <p:column headerText="Published Date 10" class="published-date-format">
                <h:outputText value="#{book.publishDate}" />
            </p:column>                                
        </p:dataTable>
    </h:form>
</h:body>

CSS 表:

.book-id-format {
height: 8px !important;
margin-top: 3px !important;
width: 180px;}

.book-name-format {
height: 8px !important;
margin-top: 3px !important;
min-width: 80px;}

.published-date-format {
height: 8px !important;
margin-top: 3px !important;
width: 80px;}

.ui-datatable-hor-scroll .ui-datatable-tablewrapper,.scrolling-div .ui-datatable-tablewrapper{
overflow: auto;
width: auto;}

.ui-datatable.ui-widget {
font-size: 50%;}

.ui-paginator {
font-size: x-small;
width: auto;
height: 26px;}

.exporter-button {
float: right;
width: 24px;
margin-right: 5px;
background: none;}

.header-calendar {
float: left;  
margin-right: 5px;}

.ui-datepicker {  
background: white;
font-size: 70%;}

【问题讨论】:

  • 请创建一个minimal reproducible example,另见www,stackoverflow.com/tags/jsf/info(例如css的相关性是什么?)。并尝试最新版本(许多问题在 5.2 和 5.3 之间已修复,可以在问题列表、博客等中阅读)
  • @Kukeltje 感谢您的评论。该代码是供人们复制的完整示例。由于桌子很宽,所以有点长。有空的时候我可以去掉一些线。我目前无法使用 5.3。
  • 我说 TRY 5.3(只是想看看在此期间是否修复了某些问题)我没有说过你应该在生产中使用它。如果它在 5.2 和 5.3 中不起作用,那么您可以使用 5.3 的源代码来查看如何使用 5.2 中的补丁来解决此问题。因为这样的事情太复杂了,没有简单的解决方案,我怀疑人们会为这样的事情创建补丁,更不用说分享了)。而知道它是固定的就是可以共享的知识......
  • 5.3 与 5.2 具有相同的行为。
  • 我结合答案再次看了你的问题。它“无法正常工作”的最重要原因之一是您弄乱了数据表的 css 以使其可滚动。数据表有一个可滚动的选项。您还使用 css 来定义列大小,不建议这样做。所以下面的答案“修复”了你破坏的东西。尝试从头开始,你很可能会看到它在没有所有 css 的情况下工作

标签: html css jsf primefaces


【解决方案1】:

如果你在 CSS 中对列宽给出完整的定义,它可能会正常工作:

.book-name-format {
height: 8px !important;
margin-top: 3px !important;
width: 80px;
min-width: 80px;
max-width: 200px;
}

【讨论】:

    猜你喜欢
    • 2013-08-30
    • 1970-01-01
    • 2022-01-14
    • 2012-09-11
    • 2013-02-24
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多