on 2014 Jun 17 8:47 PM
I'm using the sap.m.ObjectStatus as part of my status display on a given agregated list:
in view.js:
var curstat = new sap.m.ObjectStatus({
//text: "{CountDate}",
//text: oController.formatDate('{CountDate}'),
state: "Success",
text: {
parts:[{path:'CountDate'}],
formatter: 'oController.formatterCountDate'
}
});
snippet in the controller.js, the format of the CountDate value is, yyyy-mm-ddT00:00:00. goal is to remove the time part leaving only YYYY-MM-DD. I don't get any exception thrown and the date does show just not in the format I want. I feel I'm close but just can't get figure out what I may be over looking. Thanks in advance for the help.
formatterCountDate:function(t) {
try {
var d = new Date();
var T = new sap.ui.model.type.Date( {
source : {
pattern : "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'"
},
pattern : "yyyy,MM,dd",
style : "medium"
});
d = T.formatValue(t, "string");
var D = new Date(d);
return D
}//try
catch(error) {
alert(error.message);
}
},
Request clarification before answering.
Hi Jay, Is your problem solved?
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
Hi Jay, What is the data format you have in your oData model?
Can you post the data which you are sending to the formatterCountDate(), function.
Also in the formatterCountDate() function, pls have an intial condition like,
if((value!=null) && (value!=""))
{
/* format logic here */
}
Try this and let me know.
Hi Naveen, The format of the date coming in is, YYYY-MM-DDT00:00:00. It does format the date when the result includes the date, I get the proper format. It's when the record does not have a value in the countDate field, the return of empty string seems either the formatter is returning something other than just empty string and in this case, the date ends up being '1969'.
Here's my formatter logic. Thanks.
new sap.m.ObjectStatus({
state: "Success",
text: {
parts:[{path:'CountDate'}],
formatter: function(t) {
try {
if(t != null || t != '0000-00-00') {
var oDateFormat = sap.ui.core.format.DateFormat.getDateInstance({pattern: "yyyy-MM-dd"});
return oDateFormat.format( new Date(t) );
//return t;
}
else {
return "";
}
}//try
catch(error) {
alert(error.message);
}//catch
}//formatter
}
});
Hi Jay, can you try with the below code.
Also make sure your CountDate propery in OData model has Edm.DateTime datatype.
formatterCountDate : function (value) {
if((value!=null) && (value!="0000-00-00"))
{
if (value) {
var oDateFormat = sap.ui.core.format.DateFormat.getDateTimeInstance({pattern: "yyyy,MM,dd"});
return oDateFormat.format(new Date(value));
}
else { return value; }
}
else return "";
}
Let me know if you face any issues.
--Naveenraj.
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.
| User | Count |
|---|---|
| 8 | |
| 6 | |
| 5 | |
| 4 | |
| 4 | |
| 4 | |
| 3 | |
| 2 | |
| 2 | |
| 2 |
You must be a registered user to add a comment. If you've already registered, sign in. Otherwise, register and sign in.