I tried to bind an array of dates to sap.ui.unified.Calendar but without success. I am sure I am not far from the solution.
Here is the code:
var oCal = new sap.ui.unified.Calendar();
var oModel2 = new sap.ui.model.json.JSONModel([
{myDate: new Date("2018-01-10"), tt:""},
{myDate: new Date("2018-01-11"), tt:""},
{myDate: new Date("2018-01-12"), tt:""},
]);
sap.ui.getCore().setModel(oModel, "MyData3");
var oItemTemplate = new sap.ui.unified.DateRange({
startDate: "{MyData3>myDate}",
endDate: "{MyData3>myDate}"
});
oCal.bindAggregation("selectedDates", "MyData3>/", oItemTemplate);
I don't get any exception. The model has the data filled with 3 objects of type Date but I do not have those 3 dates pre-selected in the calendar.
If I fill the selectedDates
aggregation manually (without binding) it will select those 3 dates.
Here is a working minimal example:
I assume the provided code in your question is not a real excerpt from your project. Otherwise, you'd have got a ReferenceError saying that the variable
oModel
is undefined (instead,oModel2
is defined). Apart from this, the actual reason why the binding did not work must be because the model is set on the core while the Calendar control is a descendant of ComponentContainer. In that case, the Core model won't be propagated to the Component.--> Avoid setting models on the Core if the app is component-based.
If not already done: In order to display multiple selected dates in the first place, the Calendar property
singleSelection
has to be disabled explicitly since it's enabled by default.