DataTable .filter() and clearFilters() hides messa

2020-07-18 07:20发布

问题:

My issue when I use:

<p:growl id="growl" autoUpdate="true" />

or

<p:messages id="messages" autoUpdate="true" />

When I have error message, and once I use clear filters or re filter for primefaces datatable like :

<p:commandButton value="do somthing and re-filter" oncomplete="PF('testTable').filter()"/>

<p:commandButton value="do somthing and clear filter" oncomplete="PF('testTable').clearFilters()"/>

<p:dataTable id="table" widgetVar="testTable" value="#{myMB.data}">
</p:dataTable>

The messages got hidden, that because the autoUpdate is true, so ajax call for filter fired and return with no messages so this call clear messages, will be a solution if I make autoUpdate="false" but I needed it so I don't want to set it to false.

回答1:

Solution is to add ajax filter event to the p:datatable:

<p:dataTable id="table" widgetVar="testTable" value="#{myMB.data}">
    <p:ajax event="filter" ignoreAutoUpdate="true" />
    {...}
</p:dataTable>