SAPUI5-如何从表格中搜索格式化日期

SAPUI5-如何从表格中搜索格式化日期,sapui5,Sapui5,我有一个日期列,格式为MMM d,yyyy。如果用户搜索2018,我如何过滤它 XML 控制器 searchTable: function (evt) { var oTable = this.getView().byId("ordersTable"); var searchTerm = evt.getParameter("query"); if (searchTerm === "") { //

我有一个日期列,格式为MMM d,yyyy。如果用户搜索2018,我如何过滤它

XML

控制器

searchTable: function (evt) {
            var oTable = this.getView().byId("ordersTable");
            var searchTerm = evt.getParameter("query");
            if (searchTerm === "") {
                //When clear was pressed on search field
                oTable.getBinding("rows").filter(null);
            } else {
                var filters = [];
                var outerFilters = [];
                var searchTerms = searchTerm.split(" "); //words separated by space are considered as separate search terms. 
                for (var k = 0; k < searchTerms.length; k++) {

                    filters.push(new Filter("OrderType", sap.ui.model.FilterOperator.Contains, searchTerms[k]));
                    filters.push(new Filter("StartDate", sap.ui.model.FilterOperator.Contains, searchTerms[k]));
                    outerFilters.push(new Filter(filters));
                    filters = [];
                }
                oTable.getBinding("rows").filter(new Filter({
                    filters: outerFilters,
                    and: true //Default is OR between filters
                }));
            }
        },
收到日期:起始日期:2019年3月23日星期六05:30:00 GMT+0530 日期格式为:2019年3月23日


我知道“Contains”仅适用于字符串,但如何使其适用于date也适用于date我们面临类似的问题,有两种解决方案, 一个在客户端,另一个在服务器端

客户端: 在该属性上使用格式化程序将日期解析为字符串

服务器端: 请求另一个以字符串形式显示该日期的属性

查看您的代码,我可以看到您已经在使用formatter formatter.date,因此我们可以探索客户端选项

在formatter.date函数中,可以执行以下操作:

date(yourDateField)
{
   let options = { year: 'numeric', month: 'short', day: 'numeric' };
   return yourDateField.toLocaleDateString("en-US", options);
}

谢谢成功了。但对于过滤器,我使用的是从型号StartDate开始的日期。所以它一开始不起作用。我已经添加了以下代码过滤器。pushnew过滤器{path:,test:functionvalue{var formatted=formatter.datevalue.StartDate;return formatted.toLowerCase.indexOfsearchTerm>-1;};这起作用了。但加载需要2秒的时间。有没有更好的办法来处理这个问题?
date(yourDateField)
{
   let options = { year: 'numeric', month: 'short', day: 'numeric' };
   return yourDateField.toLocaleDateString("en-US", options);
}