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

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14339855/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-06 10:55:12  来源:igfitidea点击:

Ajax update doesn't work, when using filter on p:dataTable

ajaxjsffilterprimefacesdatatable

提问by Johnny2012

I have a datable which includes the filter feature of primefaces. Some operations can be done on the table (e.g. edit). The datable will be updated after the user's operation is completed using ajax. It updates the table directly and works well, if I don't filter the datatable, unfortunately not if I use it and edit it.

我有一个包含primefaces 过滤功能的数据表。可以对表进行一些操作(例如编辑)。用户使用ajax完成操作后,dataable会被更新。它直接更新表并且运行良好,如果我不过滤数据表,不幸的是如果我使用它并编辑它。

That's how my datatable looks like:

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

    <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">

and the Button which triggers the update

和触发更新的按钮

<p:commandButton value="Save"
                        actionListener="#{bean.save}"
                        update=":form"/>

回答by Kerem Baydo?an

After updating datatableyou have to invoke it's client side filter()method.

更新后的数据表,你必须调用它的客户端的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()"/>

For PrimeFaces versions older than 5, you should use

对于 5 岁以上的 PrimeFaces 版本,您应该使用

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

回答by Al-Mothafar

Adding answer for Primefaces 5.x , since they changed the way for calling widget var:

添加 Primefaces 5.x 的答案,因为它们改变了调用小部件 var 的方式:

Almost same as Kerem Baydogan's answer but with a little modification :

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

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

Or you can clear filters at all with :

或者您可以完全清除过滤器:

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

回答by KIBOU Hassan

For the version of primefaces greater or equal to 5, you can use this block of code, it works very well

对于大于等于5的primefaces的版本,可以使用这段代码,效果很好

<p:dataTable var="page" value="#{yourBean.allData}" widgetVar="yourWidgetVarName"/>

<p:commandButton value="delete"
                 actionListener="#{yourBean.delete}"
                 update="@form"
                 oncomplete="PF('yourWidgetVarName').filter()"/>

回答by Nather Webber

If you are using the version 5 of primefaces just make the data class that rapresents the single data row, to implements Serializable

如果您使用的是 primefaces 的第 5 版,只需制作表示单个数据行的数据类,即可实现 Serializable