2016-12-19 118 views
0

我有一个绑定到sap.m.Table的JSON模型。我试图基于列表“Date”(绑定到模型的属性[CreatedOn])过滤数据,服务以JSON对象格式(“/ Date(timeStamp)”)返回。该表如下:从服务器 ​​日期/日期时间客户端上的过滤器JSON模型

采样日期:

enter image description here

我想过滤的客户端表,但我不知道如何实现日期过滤器在客户端。基于

sap.ui.model.type.Date格式化显示的日期({图案: 'DD/MM/YYYY'})

滤波代码看起来如下:

var fromD = this.getView().byId("idKMFilterPaneDocDateF").getValue() ? new Date(this.getView().byId("idKMFilterPaneDocDateF").getValue()) : 
 
    undefined; 
 

 
var dtFilter = new sap.ui.model.Filter({ 
 
    path: "CreatedOn", 
 
    operator: "EQ", 
 
    value1: "dateTime'" + fromD.toJSON() + "'" 
 
}); 
 

 
var binding = oTable.getBinding("items"); 
 
binding.filter([filter], "Application"); 
 
binding.refresh();

当我执行上面的代码,我总是得到 “无数据”。我需要根据用户选择标准实施“BT”过滤器,但无法使其与“EQ”本身一起工作。

回答

1

创建自定义过滤

var fromD = this.getView().byId("idKMFilterPaneDocDateF").getValue() ? new Date(this.getView().byId("idKMFilterPaneDocDateF").getValue()) :undefined; 
var dtFilter = new sap.ui.model.Filter("CreatedOn"); 
dtFilter.fnTest = function(value) { 
    //check what value are you getting here. If its string, get only time out of it 
    //Compare the date values(in milliseconds) 
    fromD.setHours(0); //get rid of time and concern about date 
    fromD.setMinutes(0); 
    fromD.setSeconds(0); 
    fromD.setMilliseconds(0); 
    //value should be date object, else change accordingly.. 
    if(fromD.getTime() === value.getTime()){ 
     return true; 
    } 
    return false; 
}; 

PS:如果你能得到你的编码环境中工作的jsfiddle,我可以调试。

+0

谢谢苏尼尔,代码作为魅力:) – Deepak