Grü*_*üse 5 format date sapui5
我有一个从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"
}));
Run Code Online (Sandbox Code Playgroud)
这是前两行输出(我的浏览器语言是德语):

我想要做的就是将日期和时间格式更改为mm/dd/yyyy hh:mm
我做了一些搜索,以下问题正是我的问题 - 但有一个已接受的答案,我不理解或实际上没有解决问题: 表SAPUI5中的日期格式
我意识到这可能是一个微不足道的问题,我只是错过了如何轻松地做到这一点,或者它是在一个官方教程中处理的.在这种情况下,请在评论中指出我,我将删除这个问题.
qma*_*cro 16
使用格式化程序函数非常灵活,但是如果你在寻找更简单的东西而不必编写自己的格式逻辑,你可以考虑使用type属性而不是formatter这样:
template: new sap.ui.commons.TextView().bindProperty("text", {
path: "OrderDate",
type: new sap.ui.model.type.Date({pattern: "MM/dd/yyyy hh:mm"})
})
Run Code Online (Sandbox Code Playgroud)
也可能值得考虑标准模型格式化程序:sap.ui.model.type.DateTime和sap.ui.model.type.Date
template: new sap.ui.commons.TextView().bindProperty("text", {
path: "DATE",
type: new sap.ui.model.type.DateTime,
formatOptions: { style: "medium" }
})
Run Code Online (Sandbox Code Playgroud)
XML 示例(一如既往地使用 XML ;)
<Text text="{path : 'runDateTime',
type : 'sap.ui.model.type.DateTime',
formatOptions: { style : 'medium'}}" />
Run Code Online (Sandbox Code Playgroud)
由于使用 UI5 通常是关于为应用程序应用标准视图的对话,因此使用标准格式可能是一个有用的想法。
使用格式化函数:
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"
}));
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
33606 次 |
| 最近记录: |