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.
Using a formatter function is very flexible, but if you're looking for something simpler without having to write your own format logic, you can consider using the type
property rather than the formatter
like this:
template: new sap.ui.commons.TextView().bindProperty("text", {
path: "OrderDate",
type: new sap.ui.model.type.Date({pattern: "MM/dd/yyyy hh:mm"})
})