31

Primefacesのフィルター機能を含むデータブルがあります。一部の操作はテーブルで実行できます(編集など)。データブルは、ユーザーの操作がajaxを使用して完了した後に更新されます。これはテーブルを直接更新し、データテーブルをフィルタリングしない場合はうまく機能しますが、残念ながら、それを使用して編集する場合はそうではありません。

これが私のデータテーブルの外観です。

    <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

4 に答える 4

61

datatableを更新した後、そのクライアント側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()"/>
于 2013-01-15T15:24:31.897 に答える
17

Primefaces 5.xの回答を追加します。これは、ウィジェット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()"/>
于 2015-02-11T14:42:26.743 に答える
-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()"/>
于 2017-04-20T15:37:51.457 に答える
-6

Primefacesのバージョン5を使用している場合は、単一のデータ行を表すデータクラスを作成して、Serializableを実装します。

于 2015-04-10T10:12:36.490 に答える