【问题标题】:Datatable Global Filter - Unexpected Behavior数据表全局过滤器 - 意外行为
【发布时间】:2018-07-16 15:53:37
【问题描述】:

当用户按 Enter 键时,我有一个 globalfilter in a Datatable 可以工作:

它按预期过滤。但是,奇怪的是,在过滤数据表之后,p:dialog 内的 createForm 也会显示出来,这是意料之中的;此 createForm 是并且应该仅在用户单击触发它的 createButton 时显示。

以上,与组件相关的代码摘录。

createButton 和数据表:

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

<h:form id="DemandasListForm">

<p:panel id="PanelListForm">

<p:commandButton id="createButton" icon="fa fa-plus-square" value="#{adeBundle.CreateDemanda}" update=":DemandasCreateForm" oncomplete="PF('DemandasCreateDialog').show()" actionListener="#{demandasController.prepareCreate}"  />

<f:facet name="header">
    <p:outputPanel style="text-align: right">
        <p:inputText id="globalFilter" onkeypress="if (event.keyCode === 13) {PF('demandasTable').filter();}" placeholder="Type something and press ENTER." />
    </p:outputPanel>
</f:facet>

<p:dataTable id="datalist"
value="#{demandasController.items}"
lazy="false"
rowKey="#{item.id}"
var="item"
paginator="true"
paginatorPosition="bottom"
selectionMode="single"
selection="#{demandasController.selected}"
filteredValue="#{demandasController.filteredDemandas}"
filterDelay="1000" <!-- doesn't work for globalfilter, only for the columns-->
widgetVar="demandasTable">
...
</p:dataTable>

对话框:

<ui:composition>
  <p:dialog id="DemandasCreateDlg" widgetVar="DemandasCreateDialog" modal="true" appendTo="@(body)" closeOnEscape="true">
    <h:form id="DemandasCreateForm">
...

有谁知道我该如何解决这个问题?

提前致谢。

【问题讨论】:

    标签: ajax primefaces datatable global-filter


    【解决方案1】:

    可以尝试像这样返回false..

    onkeypress="if (event.keyCode === 13) {PF('demandasTable').filter(); return false;}"
    

    这将在调用过滤器方法后爆发,并且不会让 ENTER 键传播。我认为正在发生的是 ENTER 键正在提交表单上的第一个按钮,这是您的命令按钮以打开对话框。默认浏览器行为是在您按 ENTER 时提交它在表单上找到的第一个按钮。

    【讨论】:

    • Melloware,它成功了!感谢您分享您的知识,我的朋友!
    • 没问题!感谢您支持我的解决方案。
    • 你值得拥有!这是我从这里开始以来在这个论坛上收到的最快和最有效的答案。管理员应该为此创建一个徽章,你肯定会赢得它:)
    猜你喜欢
    • 1970-01-01
    • 2019-09-23
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-09-20
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多