12
votes

I am using the dataTable component with the paginator in a search utility which works great but having a problem to reset paginator page to the first page. for example you are on page 6 of the paginator and you perform a new search, the dataTable gets reloaded with the new data but, the page number is not reset to 1 it remains on 6.

I'm using PF 3.4.2. any idea?

4
show the code your search and try adding update="myTableId" to your search componentDaniel
My datatable is inside a panel "displayResult",so in the command button i did: <p:commandButton icon="ui-icon-search" value="Find" actionListener="#{searchBean.searchCertif}" update="displayResult"/>callafa
Can you post your code?Xtreme Biker
I found the solution, should add this to the CommandButton: onclick="wdg_dataTable.getPaginator().setPage(0);callafa
Please post this as an answer (you can answer your own question), and set it as accepted. Or delete this question altogether.Magnilex

4 Answers

24
votes

Add the following javascript to the action which updates the DataTable's model:

onclick="myWidgetVar.getPaginator().setPage(0);"

Where myWidgerVar is the WidgetVar for the DataTable.

Ensure that the DataTable has a WidgetVar set. For further context, see this post by Optimus Prime.

The above causes the grid to make a call to refresh data with existing filters. If you explicitly want the grid to load new data from page one, you can reset the datatable on server side

DataTable dataTable = (DataTable) FacesContext.getCurrentInstance().getViewRoot().findComponent("dialogSelectionForm:carSelectDialogTable");
dataTable.reset();

Reference - http://forum.primefaces.org/viewtopic.php?f=3&t=5807

10
votes

I solved with widgetVarDataTable.clearFilters(); in primefaces 3.5, and PF('widgetVarDataTable').clearFilters(); in primefaces 5.0

6
votes

I solved my problem using PF('dataTableWidgetVar').paginator.setPage(0); in Primefaces 6.0

2
votes

I had to solve this need in the back-end. To solve the problem without executing some sort of "duplicated refresh" I did implement this:

<p:commandButton ... update="dataTable" actionListener="#{myController.bindingDataTable.setFirst(0)}" oncomplete="someClientJS();" ... />

This code assumes the dataTable in the front-end is binding to the back-end reference variable myController.bindingDataTable. The ActionListener executes before the dataTable gets refreshed, so for that moment the paging is set with '0' as value for the first row/record (hence, first page as well).