Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Primefaces datatable reset pagination

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?

like image 985
callafa Avatar asked Aug 26 '13 10:08

callafa


2 Answers

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

like image 142
8bitjunkie Avatar answered Sep 21 '22 12:09

8bitjunkie


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

like image 40
user2532187 Avatar answered Sep 21 '22 12:09

user2532187