Sorting using rich:columns
damianharvey Mar 1, 2010 2:22 AMHi all,
I'm trying to use rich:columns to implement column re-ordering. I realise that this feature is part of the extendedDataTable however for this project I can't use it.
Using rich:columns I can display the columns as I want and all looks ok, however the sorting just won't work. The messages gets posted back to the server however the response doesn't render a sorted table.
Here is the relevant part of my page:
<rich:dataTable
id="Tpdsie"
value="#{poDetailTableList}"
sortMode="single"
selectionMode="single"
noDataLabel="#{noDataLabel}"
var="pdsi">
<rich:column status="STts" id="Cb" sortable="true" label="SKU" sortBy="#{pdsi.poDetail_sku}" rendered="#{poTableColumnManager.isSelectedColumn('SKU')}">
<f:facet name="header">SKU</f:facet>
#{pdsi.poDetail_sku}
</rich:column>
<rich:columns id="#{column.id}" value="#{poDetailColumns}" var="column" index="ind" sortBy="#{pdsi[column.value]}" rendered="#{column.rendered}">
<f:facet name="header">
#{column.label}
</f:facet>
#{pdsi[column.value]}
</rich:columns>
</rich:dataTable>
Note that the first column is there to test the sorting. Clicking on that works fine. Clicking on the same column rendered via rich:columns produces the same (very similar) AJAX message, but the while the sorting on the first column works, the second doesn't.
The column model is :
public class PoTableColumn {
private int sequence;
private String label;
private String id;
private boolean sortable;
private String sortBy;
private boolean rendered;
private String value;
public PoTableColumn(
int sequence,
String label,
String id,
boolean sortable,
boolean rendered,
String value) {
this.sequence = sequence;
this.label = label;
this.id = id;
this.sortable = sortable;
this.rendered = rendered;
this.value = value;
}
And the code that creates these columns is :
@Factory("poDetailColumns")
public List<PoTableColumn> getPoDetailColumns() {
List<PoTableColumn> cols = new ArrayList<PoTableColumn>();
cols.add(new PoTableColumn(1, "SKU", "Csku", true, true, "poDetail_sku"));
cols.add(new PoTableColumn(2, "Description", "Cdes", true, true, "poDetail_description"));
return cols;
}
I suspect that I've missed something in how the sort attribute is supposed to be defined but I can't see it. The examples are based on sorting by one column (price). Can anyone point me in the correct direction?
Thanks,
Damian.