TreeTable/Datatable: Dynamic Columns Issue
See original GitHub issue1) Environment
- PrimeFaces version: 7.0
- Does it work on the newest released PrimeFaces version? Version? NO
- Does it work on the newest sources in GitHub? (Build by source -> https://github.com/primefaces/primefaces/wiki/Building-From-Source) NO
- Application server + version: ALL
- Affected browsers: ALL
2) Expected behavior
3) Actual behavior
org.primefaces.component.api.DynamicColumn cannot be cast to org.primefaces.component.column.Column: java.lang.ClassCastException: org.primefaces.component.api.DynamicColumn cannot be cast to org.primefaces.component.column.Column
at org.primefaces.component.treetable.TreeTable.updateColumnsVisibility(TreeTable.java:655)
at org.primefaces.component.treetable.TreeTableRenderer.preRender(TreeTableRenderer.java:226)
at org.primefaces.component.treetable.TreeTableRenderer.encodeEnd(TreeTableRenderer.java:161)
4) Steps to reproduce
Press “Refresh” button
5) Sample XHTML
<h:form id="form">
<p:commandButton value="Refresh" update="@form" />
<p:commandButton id="toggler" type="button" value="Columns" style="float:right" icon="ui-icon-calculator" />
<p:columnToggler datasource="idDataTable" trigger="toggler" />
<p:treeTable id="idDataTable" var="cars" value="#{tableBean.carsTree}">
<p:column value="Column">
<h:outputText value="Column" />
</p:column>
<p:columns value="#{tableBean.columns}" var="column" columnIndexVar="columnIndx" visible="true">
<f:facet name="header">
#{column.header}
</f:facet>
<h:outputText value="#{cars[column.property]}" />
</p:columns>
</p:treeTable>
</h:form>
6) Sample bean
public class TableBean implements Serializable {
private List<ColumnModel> columns = new ArrayList<ColumnModel>();
private DefaultTreeNode carsTree = new DefaultTreeNode();
public TableBean() {
populateColumns();
Car car = new Car();
car.setManufacturer("Audi");
car.setModel("A4");
car.setYear(2015);
new DefaultTreeNode(car, carsTree);
}
public void populateColumns() {
String[] columnKeys = new String[]{"model","year","color"};
for(String columnKey : columnKeys) {
columns.add(new ColumnModel(columnKey.toUpperCase(), columnKey));
}
}
//getters and setters
public List<ColumnModel> getColumns() {
return columns;
}
public void setColumns(List<ColumnModel> columns) {
this.columns = columns;
}
public DefaultTreeNode getCarsTree() {
return carsTree;
}
public void setCarsTree(DefaultTreeNode carsTree) {
this.carsTree = carsTree;
}
static public class ColumnModel {
private String header;
private String property;
public ColumnModel(String header, String property) {
this.header = header;
this.property = property;
}
public String getHeader() {
return header;
}
public String getProperty() {
return property;
}
}
}
Issue Analytics
- State:
- Created 4 years ago
- Comments:52 (48 by maintainers)
Top Results From Across the Web
Dynamic Columns For TreeTable - PrimeFaces
Static p:column and Dynamic p:columns can be used together and sorting is also supported using a dynamic column. Live demo is available at ......
Read more >Dynamic Columns Problem — DataTables forums
I have a request where the datatable columns depend on the value of a select field. Initially the datatable has 17 columns.
Read more >Problem with 'Dynamic' row height in treetable - Webix Forum
Hi, I am using 'adjustRowHeight()' inorder to make the row height dynamic in a treetable. But the folder for treetable gets dislocated.
Read more >Jquery-TreeTable how to dynamically add columns in the tree ...
But now I have problem even in show rows, it does not show as tree in tree-table. Could you tell me where is...
Read more >Creating DataTable Programmatically with Dynamic Columns
This example demonstrates how to create dynamic DataTable with runtime column ... selectedColumns}" label="Table Columns"> <f:selectItems ...
Read more >
Top Related Medium Post
No results found
Top Related StackOverflow Question
No results found
Troubleshoot Live Code
Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free
Top Related Reddit Thread
No results found
Top Related Hackernoon Post
No results found
Top Related Tweet
No results found
Top Related Dev.to Post
No results found
Top Related Hashnode Post
No results found
i refactored it now and fixed the exception but it still doesnt work and all columns are hidden
Weird you are right its definitely a firefox issue doesn’t happen on Chrome or Edge. Let me see what I can find out.