Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Formatting a date from an ODataModel in a SAPUI5 table

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):

example output

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.

like image 817
Grüse Avatar asked May 08 '14 09:05

Grüse


People also ask

How do I change the date format in SAPUI5?

yyyy-MM-dd'T'HH:mm:ss (2019-07-03T12:34:46)

What is the use of formatter in SAPUI5?

SAP UI supports custom formatter functions. formatter="function" is used to specify a function to format cell data prior to display.


1 Answers

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"})
})
like image 103
qmacro Avatar answered Oct 03 '22 08:10

qmacro