【问题标题】:How to remove the Horizontal Scroll bar in <p:dataTable>如何删除 <p:dataTable> 中的水平滚动条
【发布时间】:2014-07-16 08:28:02
【问题描述】:

我正在尝试隐藏 .
中的水平滚动条 我尝试了许多解决方案,但似乎不起作用。 我尝试过的解决方案是here
这是我在 XHTML 中使用的代码

<ui:composition xmlns="http://www.w3.org/1999/xhtml"
    xmlns:f="http://java.sun.com/jsf/core"
    xmlns:h="http://java.sun.com/jsf/html"
    xmlns:ui="http://java.sun.com/jsf/facelets"
    xmlns:p="http://primefaces.org/ui">

    <h:form id="commentsform">
        <p:outputPanel id="commenttable">
            <p:dataTable id="commentsdt" var="row" stickyHeader="true"
                value="#{bean.displayCommentsDetailsList}"
                selection="#{bean.selectedComments}"
                rowKey="#{row.commentDate}" rows="20" paginator="true"
                paginatorPosition="bottom" rowIndexVar="index"
                paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                scrollable="true" scrollHeight="150" style="width:100%;overflow-x:hidden;overflow-y:auto;"
                rowStyleClass="#{row.changeFieldFlg==true ? 'highlight' : null}">

                <f:facet name="header">
                    <h:panelGrid columnClasses="alignRight">
                        <p:commandButton
                            disabled="#{bean.editCmdActionflg == false}"
                            actionListener="#{bean.addComments}"
                            update="commentsdt :SystemDetailsinfoForm:line :growl :error"
                            partialSubmit="true" title="Add Row.." icon="ui-icon-plusthick"
                            styleClass="iconButton" />
                    </h:panelGrid>
                </f:facet>

                <p:column width="160" headerText="Date" style="width:150px">
                    <h:outputText value="#{row.commentDate}" style="width:150px" />
                </p:column>
                <p:column width="160" headerText="Author" style="width:150px">
                    <h:outputText value="#{row.author}" style="width:150px" />
                </p:column>
                <p:column width="100" headerText="Deliverable" style="width:90px"
                    rendered="#{bean.selectedChoice == '2'}">
                    <h:outputText value="#{row.delivName}"
                        rendered="#{bean.selectedChoice == '2'}"
                        style="width:90px" />
                </p:column>
                <p:column headerText="Comments">
                    <div align="left">
                        <h:outputText value="#{row.comments}"
                            rendered="#{row.editableflg==false}"></h:outputText>
                        <p:inputTextarea value="#{row.comments}"
                            style="width:98%;float:left" rendered="#{row.editableflg==true}">
                        </p:inputTextarea>
                    </div>
                </p:column>

            </p:dataTable>
        </p:outputPanel>
    </h:form>
</ui:composition><br/>

我尝试使用溢出-y:滚动;溢出-x:隐藏;隐藏水平滚动条,但它们似乎都没有应用于数据表。
请告诉我您解决此问题的建议

【问题讨论】:

  • 我通过添加 .ui-datatable-scrollable-body { overflow-y: scroll !important; 解决了上述问题溢出-x:隐藏!重要; } 到我的默认样式表。但是此更改适用于上表,但相同的更改正在影响其他数据表,它删除了所有水平滚动条,因为它是通用的。如何将此更改应用于调用的特定数据表样式表。

标签: css jsf primefaces datatable scrollbar


【解决方案1】:

您可以添加 20 px 的高度,在我的例子中,我添加了宽度,因为我需要它的宽度。 所以我的 div 容器:

  .container {
height: 100%;
width: calc(100% + 20px);}

我使用这个技巧是因为我只想隐藏垂直滚动条,不幸的是,我不知道如何只隐藏primeng 数据表上的垂直滚动条。我希望它对你有帮助

【讨论】:

  • 你提到的已经有效的解决方案对我不起作用,这就是我提出这个的原因;)
【解决方案2】:

在我的例子中,我有一个垂直滚动条,因为单元格中使用的一种样式定义了一个非零padding
用零重新定义样式padding滚动条消失了。

【讨论】:

    【解决方案3】:

    我刚刚为 &lt;p:dataTable&gt; 制作了一个自定义样式,并在 .

    我写的风格是

    .mystyle.ui-datatable .ui-datatable-scrollable-body{
        overflow-y: scroll !important;
        overflow-x: hidden !important;
    }
    


    我在下面给出的&lt;p:dataTable&gt; 中调用了样式类 styleClass="mystyle"

    <p:dataTable id="commentsdt" var="row" stickyHeader="true"
                    value="#{systemDetailsBean.displayCommentsDetailsList}"
                    selection="#{systemDetailsBean.selectedComments}" rowKey="#{row.commentDate}"
                    rows="20" paginator="true" paginatorPosition="bottom"
                    rowIndexVar="index"
                    paginatorTemplate="{FirstPageLink} {PreviousPageLink} {CurrentPageReport} {NextPageLink} {LastPageLink}"
                    scrollHeight="150" scrollable="true" style="width:100%;"  styleClass="mystyle"
                    rowStyleClass="#{row.changeFieldFlg==true ? 'highlight' : null}">
    

    【讨论】:

    • 在我的情况下工作 - .mystyle .ui-datatable-scrollable-view .ui-datatable-scrollable-body{ overflow-y: scroll !important; overflow-x: hidden !important; }
    猜你喜欢
    • 2011-05-23
    • 1970-01-01
    • 2022-01-15
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多