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

时间:2021-10-03 19:41:40

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.

我有一个数据表,它包含了原始面的过滤特性。一些操作可以在表上完成(例如编辑)。使用ajax完成用户操作后,将更新数据。它可以直接更新表,如果我不过滤datatable,很遗憾,如果我使用它并编辑它,它就不会被删除。

That's how my datatable looks like:

这就是我的datatable看起来的样子:

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

4 个解决方案

#1


44  

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

更新datatable之后,您必须调用它的客户端过滤器()方法。

<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岁以上的原始面孔,你应该使用

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

#2


15  

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

为原始面孔添加答案5。x,因为它们改变了调用小部件var的方式:

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

几乎和凯莱姆·巴多根的回答一样,只是稍微修改一下:

<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()"/>

#3


-2  

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

对于大于或等于5的版本,你可以使用这个代码块,它工作得很好。

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

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

#4


-5  

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

#1


44  

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

更新datatable之后,您必须调用它的客户端过滤器()方法。

<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岁以上的原始面孔,你应该使用

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

#2


15  

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

为原始面孔添加答案5。x,因为它们改变了调用小部件var的方式:

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

几乎和凯莱姆·巴多根的回答一样,只是稍微修改一下:

<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()"/>

#3


-2  

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

对于大于或等于5的版本,你可以使用这个代码块,它工作得很好。

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

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

#4


-5  

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