在p:dataTable上使用过滤器时,Ajax更新不起作用

Joh*_*012 27 ajax datatable jsf filter primefaces

我有一个数据包括primefaces的过滤器功能.可以在桌面上完成一些操作(例如编辑).使用ajax完成用户操作后,将更新datable.它直接更新表并且运行良好,如果我不过滤数据表,遗憾的是如果我使用它并编辑它.

这就是我的数据表的样子:

    <p:dataTable id="dataTable" var="row"
                value="#{bean.value}"
                filteredValue="#{bean.filteredValue}"
                paginator="true" rows="25" paginatorPosition="bottom"
                rowKey="${row.id}"
                paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink}"
                editable="true">
Run Code Online (Sandbox Code Playgroud)

以及触发更新的Button

<p:commandButton value="Save"
                        actionListener="#{bean.save}"
                        update=":form"/>
Run Code Online (Sandbox Code Playgroud)

Ker*_*ğan 48

更新后的数据表,你必须调用它的客户端的filter()方法.

<p:dataTable widgetVar="dataTableWidgetVar" id="dataTable" var="row"
             value="#{bean.value}"
             filteredValue="#{bean.filteredValue}"
             paginator="true" rows="25" paginatorPosition="bottom"
             rowKey="${row.id}"
             editable="true">

<p:commandButton value="Save"
                 actionListener="#{bean.save}"
                 update=":form"
                 oncomplete="PF('dataTableWidgetVar').filter()"/>
Run Code Online (Sandbox Code Playgroud)

对于早于5的PrimeFaces版本,您应该使用

<p:commandButton value="Save"
                 actionListener="#{bean.save}"
                 update=":form"
                 oncomplete="dataTableWidgetVar.filter()"/>
Run Code Online (Sandbox Code Playgroud)

  • `filter()`方法创建另一个更新操作.如果你使用`autoUpdate ="true"`try`autoUpdate ="false"`并手动更新咆哮.你也可以把它弄糊涂.但请记住`autoUpdate ="true"`适用于简单页面.如果你需要完全控制,请不要使用`autoUpdate ="true"` (2认同)
  • 嗨Kerem,前段时间我问过你这个问题.它工作得非常好,再次感谢它.我现在面临着使用它的另一个问题.如果所选值(使用过滤器)是我的数据表的第3页中的一行,并且在行上的操作之后,分页将自动重置为第1页.我希望它将焦点保持在所选行所在的页面上,这种情况第3页.如果我手动转到第3页,该行仍处于选中状态.您对此有何建议? (2认同)

Al-*_*far 16

添加Primefaces 5.x的答案,因为他们改变了调用widget var的方式:

几乎与Kerem Baydogan的答案相同,但稍作修改:

<p:commandButton value="Save"
                 actionListener="#{bean.save}"
                 update="@form"
                 oncomplete="PF('dataTableWidgetVar').filter()"/>
Run Code Online (Sandbox Code Playgroud)

或者您可以使用以下方法清除过滤器:

<p:commandButton value="Save"
                 actionListener="#{bean.save}"
                 update="@form"
                 oncomplete="PF('dataTableWidgetVar').clearFilters()"/>
Run Code Online (Sandbox Code Playgroud)