我需要一个例子来排序ace中的列:dataTable,我不知道如何使用sortBy + sortFunction。 感谢
答案 0 :(得分:2)
所以我的朋友找到了解决方案:
在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;
}
};
Comparator的类型是我们排序的属性的类型,在这种情况下,ARecordNo类型是String
public Comparator<String> getvNoComparator() {
return vNoComparator;
}
public void setvNoComparator(Comparator<String> vNoComparator) {
this.vNoComparator = vNoComparator;
}
在.xhtml中:
<ace:dataTable
value="#{eITDocumentsCollectionBean.AEITDocumentsItems}"
var="eITDocumentsItemBean" …..
<ace:column
headerText="#{eITDocumentsCollectionBean.ARecordNumberColumnName}"
sortBy="#{eITDocumentsItemBean.ARecordNo}"
sortFunction="#{eITDocumentsCollectionBean.vNoComparator}">
ARecordNo = ItemBean中要按其排序的属性 vNoComparator =我创建的比较器
答案 1 :(得分:0)
<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>
参考 - icefaces-showcase