Reset Primefaces Pagination Selected Page on Ajax Request?

"YOU AND THE ART OF ONLINE DATING" is the only product on the market that will take you step-by-step through the process of online dating, provide you with the resources to help ensure success. Get it now!

You have to extend the DataTableRenderer of Primefaces. Create a new class, maybe it could be DataTableRendererExt that extends the DataTableRenderer.

Up vote 0 down vote favorite share g+ share fb share tw.

I'm not sure if this is a bug or just something that isn't implemented but I can't update the dataGrids page property to reset the pagination to page 1. I've bound it to an expression in my bean and update it via an ajax update, but it doesn't get updated when I clicked my button. The paginator will stay on the selected page and not reset via an ajax request.

I'm using to try to reset it. The dreamSearchBean's setCurrentPage does get called and gets passed 1 but it stays at whatever page was last selected primefaces link|improve this question edited Apr 13 '11 at 19:51 asked Apr 11 '11 at 5:03c12405340 90% accept rate.

You have to extend the DataTableRenderer of Primefaces. Create a new class, maybe it could be DataTableRendererExt that extends the DataTableRenderer. Override the encodeMarkup(...) method, copy the origin code, and insert a call to resetPagination(): @Override protected void encodeMarkup(FacesContext context, DataTable table) throws IOException{ ResponseWriter writer = context.

GetResponseWriter(); ... if(hasPaginator) { table.resetPagination(); table.calculatePage(); } To bind this extended class in your application you have to insert this block in your faces-config. Xml: org.primefaces. Component org.primefaces.component.

DataTableRenderer your.package. DataTableRendererExt There is another bug in the DataTableRenderer - lazyLoading. Data table is empty on the very first load because of incorrect placement of table.loadLazyData() in the encodeTbody(...) method.

Here is my code for the extension class: public class DataTableRendererExt extends DataTableRenderer { @Override protected void encodeMarkup(FacesContext context, DataTable table) throws IOException{ ResponseWriter writer = context. GetResponseWriter(); String clientId = table. GetClientId(context); boolean scrollable = table.isScrollable(); String containerClass = scrollable?

DataTable. CONTAINER_CLASS + " " + DataTable. SCROLLABLE_CONTAINER_CLASS : DataTable.

CONTAINER_CLASS; containerClass = table.getStyleClass()! = null? ContainerClass + " " + table.getStyleClass() : containerClass; String style = null; boolean hasPaginator = table.isPaginator(); String paginatorPosition = table.

GetPaginatorPosition(); if(hasPaginator) { table.resetPagination(); table.calculatePage(); } writer. StartElement("div", table); writer. WriteAttribute("id", clientId, "id"); writer.

WriteAttribute("class", containerClass, "styleClass"); if((style = table.getStyle())! = null) { writer. WriteAttribute("style", style, "style"); } encodeFacet(context, table, table.getHeader(), DataTable.

HEADER_CLASS); if(hasPaginator &&! PaginatorPosition. EqualsIgnoreCase("bottom")) { encodePaginatorMarkup(context, table, "top"); } if(scrollable) { encodeScrollableTable(context, table); } else { encodeRegularTable(context, table); } if(hasPaginator &&!

PaginatorPosition. EqualsIgnoreCase("top")) { encodePaginatorMarkup(context, table, "bottom"); } encodeFacet(context, table, table.getFooter(), DataTable. FOOTER_CLASS); if(table.

IsSelectionEnabled()) { encodeSelectionHolder(context, table); } writer. EndElement("div"); } /** * @see org.primefaces.component.datatable. DataTableRenderer#encodeTbody(javax.faces.context.

FacesContext, org.primefaces.component.datatable. DataTable) * Fix for lazy load bug: data table is empty on very first load because of wrong palcement of table.loadLazyData(); */ @Override protected void encodeTbody(FacesContext context, DataTable table) throws IOException { ResponseWriter writer = context. GetResponseWriter(); String rowIndexVar = table.getRowIndexVar(); String clientId = table.

GetClientId(context); String emptyMessage = table.getEmptyMessage(); String selectionMode = table. GetSelectionMode(); String columnSelectionMode = table. GetColumnSelectionMode(); String selMode = selectionMode!

= null? SelectionMode : columnSelectionMode! = null?

ColumnSelectionMode : null; Object selection = table.getSelection(); if(table.isLazy()) { table.loadLazyData(); } int rows = table.getRows(); int first = table.getFirst(); int rowCount = table.getRowCount(); int rowCountToRender = rows == 0? RowCount : rows; boolean hasData = rowCount > 0; String tbodyClass = hasData? DataTable.

DATA_CLASS : DataTable. EMPTY_DATA_CLASS; writer. StartElement("tbody", null); writer.

WriteAttribute("id", clientId + "_data", null); writer. WriteAttribute("class", tbodyClass, null); if(hasData) { if(selectionMode! = null && selection!

= null) { handlePreselection(table, selectionMode, selection); } for(int I = first; I WriteAttribute("class", DataTable. ROW_CLASS, null); writer. StartElement("td", null); writer.

WriteAttribute("colspan", table.getColumns().size(), null); writer. Write(" "); writer. EndElement("td"); writer.

EndElement("tr"); } writer. EndElement("tbody"); //Cleanup table. SetRowIndex(-1); if(rowIndexVar!

= null) { context. GetExternalContext().getRequestMap(). Remove(rowIndexVar); } } }.

I would think the faces-config. Xml entry is what tells Primefaces to use the overridden version of the DataTableRenderer – c12 Aug 16 '11 at 0:24 Yes, what you declare in the render-kit block in faces-config. Xml will be used.

But in PF 3.0 this bug is fixed, you need this workaround only und 2. X – Raimo Dec 30 '11 at 13:26.

I never used it but in Primefaces documentation there is an attribute page for p:dataGrid. The description is the following: Index of the current page, first page is 1 (type: Integer, default: 1) Maybe you can use an el expression and reset the value from your backing bean when a new search is started.

Good idea, i'll give it a shot! Thanks Matt! – c12 Apr 11 '11 at 8:44 unfortunately this didn't work...It works at load but doesn't get updated when I make an ajax call even if I update the dataGrid in the commandButton's update method.

– c12 Apr 13 '11 at 19:36 I updated my example with your suggestion above. – c12 Apr 13 '11 at 19:52 Did you try updating the whole form? – Matt Handy 12 Apr7 at 19:58 yeah I tried that Matt.

– c12 Apr 21 '11 at 21:23.

Using Primefaces 3.2 I get a similar problem when I do a query and when I get, for example, five pages, then I do a new query and the page count would be 10 but it will default to the previous query and stay a page 5. The solution to reset to page one is below: DataTable dataTable = (DataTable) FacesContext. GetCurrentInstance().getViewRoot().

FindComponent("documentSearch:searchFormCase:documentSearchTable"); dataTable. SetFirst(0); Even though I am using: import org.primefaces.component.datatable. DataTable; It should work on the component below: import org.primefaces.component.datagrid.DataGrid.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions