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

时间:2013-01-15 14:27:29

标签: ajax jsf filter primefaces datatable

我有一个数据包,其中包括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">

和触发更新的按钮

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

4 个答案:

答案 0 :(得分:45)

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

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

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

答案 1 :(得分:15)

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

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

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

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

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

答案 2 :(得分:-2)

对于大于或等于5的primefaces版本,你可以使用这段代码,它运作得很好

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

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

答案 3 :(得分:-6)

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

相关问题