在SAPUI5表格中的ODataModel格式化日期 [英] Formatting a date from an ODataModel in a SAPUI5 table

查看:432
本文介绍了在SAPUI5表格中的ODataModel格式化日期的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个从OData模型填充的SAPUI5表。其中一列是我想格式化的日期/时间字段,但我无法弄清楚如何在SUI5中执行此操作。



这是什么我现在在做:

  var tableModel = new sap.ui.model.odata.ODataModel(...) ; 
var table = new sap.ui.table.DataTable();
table.setModel(tableModel);
table.addColumn(new sap.ui.table.Column({
label:new sap.ui.commons.Label({text:Date}),
template:new sap .ui.commons.TextView()。bindProperty(text,DATE),
sortProperty:DATE,
filterProperty:DATE
}));

这是第一行输出(我的浏览器语言是德语):





所有我想做的是将日期和时间格式更改为,例如mm / dd / yyyy hh:mm



我做了一些搜索,以下问题正是我的问题 - 但是有一个可以接受的答案,我不明白,或者实际上并不解决问题:
表格SAPUI5中的日期格式



我意识到这可能是一个琐碎的问题,我刚刚错过了这样做很容易,或者在官方教程之一中处理。在这种情况下,请点击我的意见,我会删除这个问题。

解决方案

使用格式化函数:

  var tableModel = new sap.ui.model.odata.ODataModel(...); 
var table = new sap.ui.table.DataTable();
table.setModel(tableModel);
table.addColumn(new sap.ui.table.Column({
label:new sap.ui.commons.Label({text:Date}),
template:new sap .ui.commons.TextView({
text:{
path:'DATE',
formatter:function(value){
return / * TODO:some format logic * ;
}
}
}),
sortProperty:DATE,
filterProperty:DATE
}));


I have got a SAPUI5 table that is populated from an OData Model. One of its columns is a date/time field that I'd like to format, but I can't figure out how to do it in SUI5.

This is what I'm doing now:

var tableModel = new sap.ui.model.odata.ODataModel("...");
var table = new sap.ui.table.DataTable();
table.setModel(tableModel);
table.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "Date"}),
    template: new sap.ui.commons.TextView().bindProperty("text", "DATE"),
    sortProperty: "DATE",
    filterProperty: "DATE"
}));

Here's the first couple of lines of output (my browser language is German):

All I want to do is change the date and time format to, say, mm/dd/yyyy hh:mm

I did some searching, and the following question is exactly my problem - but there is an accepted answer that either I do not understand or that does not actually solve the problem: Date format in a table SAPUI5

I realize this might be a trivial question and I just missed how to do this easily, or it is dealt with in one of the official tutorials. In that case, please just point me to it in the comments and I will delete this question.

解决方案

use formatter-function:

var tableModel = new sap.ui.model.odata.ODataModel("...");
var table = new sap.ui.table.DataTable();
table.setModel(tableModel);
table.addColumn(new sap.ui.table.Column({
    label: new sap.ui.commons.Label({text: "Date"}),
    template: new sap.ui.commons.TextView({
        text : { 
            path : 'DATE',
            formatter : function(value){
                return /* TODO: some format logic */;
            }
        }
    }),
    sortProperty: "DATE",
    filterProperty: "DATE"
}));

这篇关于在SAPUI5表格中的ODataModel格式化日期的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆