I need an example for sorting a column in ace:dataTable, i don't know how to use sortBy + sortFunction . thanks
0
votes
2 Answers
2
votes
So my friend found the solution:
In the collectionBean :
private Comparator<String> vNoComparator = new Comparator<String>(){
public int compare(String iRec1, String iRec2){
if(iRec1==null || iRec2==null)
{
if(iRec1==null && iRec2==null)
return 0;
if(iRec1==null)
return -1;
return 1;
}
long vNumber1= Long.parseLong(iRec1) ;
long vNumber2= Long.parseLong(iRec2);
if(vNumber1>vNumber2)
return 1;
else if(vNumber1<vNumber2)
return -1;
else
return 0;
}
};
The type of Comparator is the type of the attribute that we sort by , in this case ARecordNo type is String
public Comparator<String> getvNoComparator() {
return vNoComparator;
}
public void setvNoComparator(Comparator<String> vNoComparator) {
this.vNoComparator = vNoComparator;
}
In .xhtml :
<ace:dataTable
value="#{eITDocumentsCollectionBean.AEITDocumentsItems}"
var="eITDocumentsItemBean" …..
<ace:column
headerText="#{eITDocumentsCollectionBean.ARecordNumberColumnName}"
sortBy="#{eITDocumentsItemBean.ARecordNo}"
sortFunction="#{eITDocumentsCollectionBean.vNoComparator}">
ARecordNo= the attribute in the ItemBean to sort by it vNoComparator= the Comparator I create
0
votes
<ui:param name="title" value="#{msgs[dataTableSorting.title]}"/>
<ui:param name="description" value="#{msgs[dataTableSorting.description]}"/>
<ui:param name="resourceValue" value="#{dataTableSorting.exampleResource}"/>
<ui:param name="wikiResources" value="#{dataTableResources.wikiResources}"/>
<ui:param name="tldResources" value="#{dataTableResources.tldResources}"/>
<ui:define name="example">
<h:form id="form">
<ace:dataTable id="carTable"
value="#{dataTableSort.carsData}"
var="car">
<ace:column id="id" headerText="ID" sortBy="#{car.id}">
<h:outputText id="idCell" value="#{car.id}"/>
</ace:column>
<ace:column id="name" headerText="Name" sortBy="#{car.name}">
<h:outputText id="nameCell" value="#{car.name}"/>
</ace:column>
<ace:column id="chassis" headerText="Chassis" sortBy="#{car.chassis}" >
<h:outputText id="chassisCell" value="#{car.chassis}"/>
</ace:column>
<ace:column id="weight" headerText="Weight (lbs)" sortBy="#{car.weight}">
<h:outputText id="weightCell" value="#{car.weight}"/>
</ace:column>
<ace:column id="accel" headerText="Accel" sortBy="#{car.acceleration}" >
<h:outputText id="accelCell" value="#{car.acceleration}"/>
</ace:column>
<ace:column id="mpg" headerText="MPG" sortBy="#{car.mpg}">
<h:outputText id="mpgCell" value="#{car.mpg}"/>
</ace:column>
<ace:column id="cost" headerText="Cost" sortBy="#{car.cost}">
<h:outputText id="costCell" value="#{car.cost}">
<f:convertNumber type="currency"
currencySymbol="$"
groupingUsed="true"
minFractionDigits="2"
maxFractionDigits="2"/>
</h:outputText>
</ace:column>
</ace:dataTable>
</h:form>
</ui:define>
Reference - icefaces-showcase