2017-04-07 42 views
0

我们有一个sap.m.Table,并在一列中将值格式化并显示在UI中。 SO,让我们假设来自后端的数据是:“EventDateTime”:“2017-04-05T12:32:35.276Z”。过滤格式化的值而不是模型绑定

我们还收到这样一个时间戳的时区。

现在,我们使用时区转换接收的数据,并以06:32 04/04/2017格式显示数据。

现在,我们需要应用列过滤器表。正如你所看到的,后端数值与(由于时区转换,数据可见是一天之后)显示的数值存在差异。现在,我们希望将过滤器应用于UI中显示的格式化值,而不是UI中存在的值。

所以目前我们有一个基本的过滤器的日期,如:

new sap.ui.model.Filter({ path: sPath, operator: "BT", value1: aValue[1], value2: aValue[2] })

考虑这个虚拟数据:

{ 
    "root":[ 
     { 
     "EventDateTime":"2017-03-14T17:04:22.856-05:00", 
     "CreateDateTime":"2017-03-10T19:38:11-05:00", 
     "WaybillId":827xxxx330697, 
     "WaybillSerialNumber":60xx4277, 
     "KillReason":"EMPTY", 
     "KillDateTime":"2017-03-29T22:20:00-05:00", 
     "WaybillNumber":2xx71, 
     "ServiceOrderDateTime":"2017-03-10T19:38:00-05:00", 
     "EventTimeZone":"EST", 
     "CreateDateTimeZone":"EST" 
     }, 
     { 
     { 
     "EventDateTime":"2017-04-14T17:04:22.856-05:00", 
     "CreateDateTime":"2017-03-10T19:38:11-05:00", 
     "WaybillId":82784xxx0697, 
     "WaybillSerialNumber":6033xxx4277, 
     "KillReason":"EMPTY", 
     "KillDateTime":"2017-03-29T22:20:00-05:00", 
     "WaybillNumber":2xx2071, 
     "ServiceOrderDateTime":"2017-03-10T19:38:00-05:00", 
     "EventTimeZone":"MDT", 
     "CreateDateTimeZone":"IST" 
     } 
     } 
    ] 
} 

请帮助。

回答

0

你需要一个test功能传递给过滤器,返回truefalse根据您的病情:

new sap.ui.model.Filter({ 
     path: sPath, 
     test: function(value){ // value is the actual value from the cell 
     return value === yourCondition; //here you check the value against your condition 
     } 
}); 

编辑:过滤由多个条件

new sap.ui.model.Filter({filters: [ 
         new sap.ui.model.Filter({ 
          path: sPath, 
          test: function (value) { // value is the actual value from the cell 
           return value === sQuery; //here you check the value against your condition 
          } 
         }), 
         new sap.ui.model.Filter({ 
          path: sPath2, //Same or different path 
          test: function (value) { 
           return secondCheck(value); //different condition 
          } 
         }) 
        ], and: true //set to false for "or" behaviour 
}) 

编辑2:传递根元素作为sPath

new sap.ui.model.Filter({ 
      path: "", //Instead of matching "{EventDateTime}" we bind the entire object 
      test: function(value){ 
      return isEqual(value.EventDateTime, value.EventTimeZone); 
      } 
    }); 

文档:https://sapui5.hana.ondemand.com/#docs/api/symbols/sap.ui.model.Filter.html

+0

我需要多个值传递给测试功能。有什么办法可以将整个当前节点传递给测试函数吗?我卡在那里。 –

+0

@RahulBhardwaj我用一系列过滤器扩展了我的答案。您可以像使用逻辑条件一样对“Filters”进行分组和组合。那是你需要的吗?如果您觉得您需要将整个节点传递给'test'函数,这可能意味着您的sPath过于具体。如果要将整个对象传递给函数,您甚至可以尝试使用空的'sPath'(“”)。 –

+0

谢谢,但我同时需要两个值。根据2个参数,我修改第一个参数,然后我可以返回true或false。 –