I use primefaces 3.1 and I have a datatable that shows paginated data, whose columns are constructed based on the data of the page and rendered via <p:columns/> tag. With this approach, different pages of the same datatable can have different columns. I tought it would re-render columns on pagination by default, but it doesn't. Ive tried <p:ajax event="page" update="myTable"/> and <p:ajax event="page" update="myTableContainer"/> with any luck.
Is there a way to re-render the whole datatable when pagination is triggered, so not only content but column headers are showed properly?
Edit: Heres some code sample as you requested.
Ive made my own implementation of LazyDataModel and extended it overriding the load method implementation:
@Override
public List<StockItem> load(int i, int i1, String string, SortOrder sortOrder, Map<String, String> map) {
List<StockItem> stockItems = super.load(i, i1, string, sortOrder, map);
inventoryMovements = service.listInventoryMovements(stockItems, fromDate, toDate);
stockOperations = new HashSet<StockOperation>();
quantityTypes = new HashSet<QuantityType>();
for (Map.Entry<StockItem, ItemMovements> entry : inventoryMovements.entrySet()) {
quantityTypes.addAll(entry.getValue().getStartingQuantities().keySet());
quantityTypes.addAll(entry.getValue().getEndingQuantities().keySet());
stockOperations.addAll(entry.getValue().getOperationsApplied().keySet());
}
return stockItems;
}
As you see in the method, i fill both stockOperations and quantityTypes on every page load. These two correspond to my actual page columns. (These are atributes in my LazyDataModel implementation with their corresponding getters)
<p:dataTable id="movementsTable" var="item"
value="#{inventoryMovementsBean.view}"
rowIndexVar="rowIndex"
paginator="true"
rows="25">
<p:column headerText="Item">
<h:outputText value="#{item.label}" />
</p:column>
<p:columns value="#{inventoryMovementsBean.view.quantityTypes}" var="quantityType" columnIndexVar="quantityTypeIndex">
<f:facet name="header">
#{quantityType.description}
</f:facet>
<h:outputText value="#{inventoryMovementsBean.view.getStartingQuantity(item, quantityType)} => #{inventoryMovementsBean.view.getEndingQuantity(item, quantityType)}" />
</p:columns>
<p:columns value="#{inventoryMovementsBean.view.stockOperations}" var="stockOperation" columnIndexVar="stockOperationIndex">
<f:facet name="header">
#{stockOperation.name}
</f:facet>
<h:outputText value="#{inventoryMovementsBean.view.getOperationValue(item, stockOperation)}" />
</p:columns>
</p:dataTable>
inventoryMovementsBean.view is my LazyDataModel instance and methods getOperationValue(item, stockOperation), getStartingQuantity(item, quantityType) and getEndingQuantity(item, quantityType) are the ones that give me the content given an item and a column.
Ive already made a debug, and im pretty sure the whole data is loaded propertly, it is just a display problem. Here are some screenshots as additional information.



These images correspond to:
- Initial render (Page 1).
- Actual render after pagination (Page 3)
- Expected render after pagination (Page 3)
@ViewScoped, and your data to hold your<p:columns>persist on every new page call? - Luiggi Mendoza