Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/opencv/3.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Primefaces p:数据表排序时间_Primefaces_Datatable - Fatal编程技术网

Primefaces p:数据表排序时间

Primefaces p:数据表排序时间,primefaces,datatable,Primefaces,Datatable,我有一个PrimeFaces数据表,如下所示: <p:dataTable id="datatable_current_month_timesheets" value="#{timesheetBean.currentMonthTimesheets}" var="item"> <p:column headerText="starttimeDate" sortBy="#{item.starttime}"> <h:ou

我有一个PrimeFaces数据表,如下所示:

<p:dataTable
        id="datatable_current_month_timesheets"
        value="#{timesheetBean.currentMonthTimesheets}" var="item">
    <p:column headerText="starttimeDate" sortBy="#{item.starttime}">
        <h:outputText value="#{item.starttime}">
            <f:convertDateTime pattern="EEE, dd.MM.yyyy" />
        </h:outputText>
    </p:column>
    <p:column headerText="starttimeTime" sortBy="#{item.starttime}"> //how to sort this?
        <h:outputText
            value="#{item.starttime}">
            <f:convertDateTime pattern="HH:mm" />
        </h:outputText>
    </p:column>
    <p:column headerText="timeGap" sortBy="#{item.starttime}"> //how to sort this?
        <h:outputText
            value="#{timesheetBean.calculateTimeGap(item)}">
            <f:convertDateTime pattern="HH:mm" />
        </h:outputText>
    </p:column>
</p:dataTable>

//如何分类?
//如何分类?
第一列get sortet right,因为它是按日期排序的,不会给我带来任何问题。 但是,第二列的值与第一列的值基本相同,只是时间单位为小时:分钟。 第三列对时间进行一些计算,并获取时间。 由于我不保存这些值,我不知道如何按时间排序

例如,12:00在07:00之后和14:35之前。 如何实现这一点?

使用类似

<p:column headerText="starttimeTime" sortBy="#{item.starttime}" sortFunction="#{timesheetBean.customSort}">

您在
中的排序决定了您作为方法参数接收到的内容。因此,如果您的计算涉及日期以外的其他属性,只需使用
sortBy=“#{item}”
传输整个项目,并在上述方法中正确地转换参数。

听起来像是您需要在p:column上使用自定义排序函数,但如果值是动态生成的,我将如何排序?我可以在不指定“sortBy”的情况下进行排序吗?
public int customSort(Object o1, Object o2) {
    Date d1 = (Date) o1;
    Date d2 = (Date) o2;

    // compare d1 and d2 anyway you like and return -1, 0 or 1

}