source

p:dataTable에서 필터를 사용할 때 Ajax 업데이트가 작동하지 않음

myloves 2023. 3. 4. 15:27

p:dataTable에서 필터를 사용할 때 Ajax 업데이트가 작동하지 않음

prime faces의 필터 기능을 포함한 데이터 테이블을 가지고 있습니다.일부 작업은 테이블에서 수행할 수 있습니다(예: 편집).데이터 파일은 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"/>

데이터 테이블을 업데이트한 후 클라이언트 측을 호출해야 합니다.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()"/>

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()"/>

5 이상의 prime faces 버전에서는 이 코드 블록을 사용할 수 있습니다. 매우 잘 작동합니다.

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

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

prime faces 버전5 를 사용하고 있는 경우는, 1 개의 데이터 행에 rapresent 하는 데이터 클래스를 작성해, Serializable 를 실장합니다.

언급URL : https://stackoverflow.com/questions/14339855/ajax-update-doesnt-work-when-using-filter-on-pdatatable