I have the following problem: I want to order my list of datatables with the sorting functionality of datatable, but the problem is that I don't know the number of datatables if not at runtime.
<p:tabView>
<ui:repeat>
....
<p:dataTable var="value" value="#{myCtrl.getValues(thisTable)}">
<p:column headerText="MyClass"
sortBy="#{value.name}"
style="width:30%">
...
</ui:repeat>
</p:tabView>
I found this response that says I should hold a List to let the datatable order my elements: Sorting is not working in datatable in PrimeFaces? But the problem is that I don't know how many lists should I create in the backing bean to hold the results of each table. Does someone know how I can approach the problem?
EDIT: The model that I use is:
@ViewScoped
public class MyCtrl implements Serializable {
private String FIRST_TABLE = ...;
@Inject
private transient MyService service;
private Map<String, MyClass> tableValues = new TreeMap<>();
@PostConstruct
public void postConstruct() {
//initialize the map with a default table
tableValues.put(FIRST_TABLE, service.getTable(FIRST_TABLE);
}
List<MyClass> getValues(String table) {
if(tableValues.get(table) == null)
tableValues.put(table, service.getTable(table));
return tableValues.get(table);
}
...
}
EDIT 2: The problem is, when I click on the first column of one of the various tables that I created, defined as MyClass.name, it performs no sort, even if it calls again the method myCtrl.getValues(String table).
Primefaces version: 6.1