Jsf 删除行后,Datatable不会更新
我有一个使用primefaces库的datatable,虽然我已经使用了所有的函数,但我只有一个小问题,当我按下命令链接删除行时,它工作了,行也被删除了,但它不会自动更新datatable以反映这一点,理想情况下,我想要的是当用户按下delete按钮时,它会自动更新datatable以显示这一点,我如何实现这一点 这是数据表Jsf 删除行后,Datatable不会更新,jsf,primefaces,datatable,Jsf,Primefaces,Datatable,我有一个使用primefaces库的datatable,虽然我已经使用了所有的函数,但我只有一个小问题,当我按下命令链接删除行时,它工作了,行也被删除了,但它不会自动更新datatable以反映这一点,理想情况下,我想要的是当用户按下delete按钮时,它会自动更新datatable以显示这一点,我如何实现这一点 这是数据表 <p:dataTable id="UserTable"
<p:dataTable id="UserTable"
widgetVar="usersTable"
value="#{userdetailsController.items}"
var="item"
emptyMessage="No details was found with given criteria">
<!--filteredValue="{userdetailsController.filteredUsers}" -->
<f:facet name="header">
<p:outputPanel>
<h:outputText value="Search all fields: " />
<p:inputText id="globalFilter" onkeyup="usersTable.filter()" style="width:150px" />
</p:outputPanel>
</f:facet>
<p:column id="USERID" filterBy="id"
headerText="i.d."
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="#{bundle.ListUserdetailsTitle_id}"/>
</f:facet>
<h:outputText value="#{item.id}"/>
</p:column>
<!--There are four different match modes, "startsWith"(default), "endsWith", "contains" and "exact"-->
<p:column id="USERNAME" filterBy="username"
headerText="username."
filterMatchMode="contains">
<f:facet name="header">
<h:outputText value="#{bundle.ListUserdetailsTitle_username}"/>
</f:facet>
<h:outputText value="#{item.username}"/>
</p:column>
<p:column>
<f:facet name="header">
<h:outputText value=" "/>
</f:facet>
<p:commandLink action="#{userdetailsController.prepareView}" value="#{bundle.ListUserdetailsViewLink}"/>
<h:outputText value=" "/>
<div class="divider"/>
<p:commandLink action="#{userdetailsController.prepareEdit}" value="#{bundle.ListUserdetailsEditLink}"/>
<h:outputText value=" "/>
<div class="divider"/>
<p:commandLink action="#{userdetailsController.destroy}" value="#{bundle.ListUserdetailsDestroyLink}"/>
</p:column>
</p:dataTable>
您需要使用p:commandLink的update属性告诉PF您希望执行ajax请求以获取与表UserTable相关的所有数据,如下所示:
<p:commandLink actionListener="#{userdetailsController.destroy}" value="#{bundle.ListUserdetailsDestroyLink}" ajax="true" update="UserTable"/>
确保使用actionListener,因为它是在ActionAtrib之前调用的。这里有一个更详细的例子
您需要使用p:commandLink的update属性告诉PF您希望执行ajax请求以获取与表UserTable相关的所有数据,如下所示:
<p:commandLink actionListener="#{userdetailsController.destroy}" value="#{bundle.ListUserdetailsDestroyLink}" ajax="true" update="UserTable"/>
确保使用actionListener,因为它是在ActionAtrib之前调用的。这里有一个更详细的例子
根据,删除行后需要调用Draw()
var table = $('#example').DataTable();
$('#example tbody').on( 'click', 'img.icon-delete', function () {
table
.row( $(this).parents('tr') )
.remove()
.draw();
} );
根据,删除行后需要调用Draw()
var table = $('#example').DataTable();
$('#example tbody').on( 'click', 'img.icon-delete', function () {
table
.row( $(this).parents('tr') )
.remove()
.draw();
} );