【问题标题】:Datatable does not update after rows removed删除行后数据表不更新
【发布时间】:2013-11-17 23:00:22
【问题描述】:

我有一个使用 primefaces 库的数据表,虽然我的所有功能都在工作,但我只有一个小问题,当我按下命令链接删除行时,它可以工作并且行被删除但它没有自动更新数据表以反映这一点,理想情况下我想要的是当用户按下删除按钮时它会自动更新数据表以显示这一点,我该如何实现?

这是数据表

                        <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="&nbsp;"/>
                                </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>

【问题讨论】:

    标签: jsf primefaces datatable


    【解决方案1】:

    你需要使用p:commandLink的update属性告诉PF你想通过ajax请求获取所有与表UserTable相关的数据,如下所示:

                <p:commandLink actionListener="#{userdetailsController.destroy}" value="#{bundle.ListUserdetailsDestroyLink}" ajax="true" update="UserTable"/>
    

    确保使用 actionListener,因为它在 action atrib 之前被调用。更详细的例子是here http://www.primefaces.org/showcase/ui/commandLink.jsf

    【讨论】:

      【解决方案2】:

      根据documentation,您需要在删除一行后调用 Draw()。

      var table = $('#example').DataTable();
      
      $('#example tbody').on( 'click', 'img.icon-delete', function () {
          table
              .row( $(this).parents('tr') )
              .remove()
              .draw();
      } );
      

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2017-06-28
        • 2012-08-03
        • 1970-01-01
        相关资源
        最近更新 更多