过滤格式化值而不是模型绑定

时间:2017-04-07 08:17:02

标签: javascript sapui5

我们有一个sap.m.Table,在一列中,值被格式化并显示在UI中。 因此,我们假设来自Backend的数据是:" 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"
      }
      }
   ]
}

请帮忙。

1 个答案:

答案 0 :(得分: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