UI5 formatter not working

740 views Asked by At

I'm having troubles to get this simple formatter to work, and I don't know what's wrong.

ap.ui.jsview("splitapp.DetailPage", {

    getControllerName: function() {
        return "splitapp.DetailPage";
    },

    createContent: function(oController) {

        jQuery.sap.require("sap.ui.core.format.DateFormat");

        var oType = new sap.ui.model.type.DateTime({
            source: {
                pattern: "yyyy-MM-dd HH:mm:ss Z"
            }
        });
        var oDateFormat = sap.ui.core.format.DateFormat.getInstance({
            pattern: "MM/dd/yyyy"
        });

        oLayout.createRow(new sap.ui.commons.TextView({
                text: "Fecha de apertura",
                design: sap.ui.commons.TextViewDesign.Bold
            }),
            new sap.ui.commons.TextView({
                text: {
                    path: "ticketSelected>/fechaApertura",
                    type: oType,
                    formatter: function(d) {
                        return oDateFormat.format(new Date(d))
                    }
                }
            })
        );
    }
});
1

There are 1 answers

1
Sunil B N On BEST ANSWER

the only problem would be your d value in formatter would be "" empty string..

formatter: function(d) {
    var date = new Date(); //or any default value you want to set
    if (d) {
        date = new Date(d);
    }
    return oDateFormat.format(date);
}

Working JSFiddle here