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