使用自定义函数对primefaces数据表中的列进行排序

时间:2015-04-07 20:29:56

标签: jsf primefaces datatable

我有一个使用延迟加载和分页实现的数据表。我已经为这个元素定义了下一个属性:

<p:dataTable 
                             id="receiverList" 
                             var="receiver" 
                             widgetVar="receiverListVar"
                             value="#{receiverListBean.receiversModel}"  
                             filterDelay="750"
                             lazy="true" 
                             emptyMessage="#{text['list.empty']}" 
                             rows="20"
                             paginator="true"
                             paginatorTemplate="{CurrentPageReport}  {FirstPageLink} {PreviousPageLink} {PageLinks} {NextPageLink} {LastPageLink} {RowsPerPageDropdown}"
                             currentPageReportTemplate="{startRecord} - {endRecord} ({totalRecords})"
                             paginatorPosition="bottom"
                             style="text-align: center;margin:0;"   
                             rowsPerPageTemplate="15,20,25"
                             rowStyleClass="text-center #{(receiver.state eq 'CLOSED' or  receiver.state eq 'SIGNED' or receiver.state eq 'CANCELED')? 'tag-verde ' : 'tag-vermelha '}"
                             resizableColumns="true"
                             selection="#{receiverListBean.selectedMultipleReceivers}"  
                             filteredValue="#{receiverListBean.filteredReceivers}"
                             tableStyleClass="table table-condensed table-bordered"  
                             sortBy="#{receiver.expediteDate}"  
                             sortOrder="descending"
                             rowKey="#{receiver.id}"> 

 <p:column  
                  headerText="#{text['expedition.refExpedition']}" 
                  rendered="#{receiverListBean.viewColumn('refExpedition')}"
                  sortBy="#{receiver.expediteNumberDisplay}"
                  sortFunction="#{receiverListBean.mySort}" style="width:10%;">
                                <h:outputText value="#{not empty receiver.expediteNumberDisplay ? receiver.expediteNumberDisplay : '-'}"/>
</p:column> 

...

负责此数据表的bean具有使用属性expediteNumberDisplay对列进行自定义排序的功能。 expediteNumberDisplay是一个String,我需要实现一个包含在此Object中的数字的排序方法(比如将字符串拆分为&#34; \&#34;并根据该操作的结果计算顺序)。

public int mySort(String s1, String s2) {

        Integer score = 0;
        Integer score2 = 0;

        String[] result = s1.split("/");
        if(result.length == 2)
            score = Integer.parseInt(result[0]) + Integer.parseInt(result[1]);

        String[] result2 = s2.split("/");
        if(result2.length == 2)
            score2 = Integer.parseInt(result2[0]) + Integer.parseInt(result2[1]);

        System.out.println("Entrei no score");

        return score2.compareTo(score);
    }

模型

public class Receiver
{
...
//format number/year
private String expediteNumberDisplay;
..
}

我尝试放置mySort(对象s1,对象s2),然后施放对象但没有任何反应。我做了不同的方法,但排序功能从来没有达到任何想法?

0 个答案:

没有答案