cancel
Showing results for 
Search instead for 
Did you mean: 

Binding rows aggregation for Planning Calendar

Former Member
0 Kudos

Hi,

In my controller, I am creating a named model on the PlanningCalendar control and trying to bind the rows aggregation's path.


var oModel = this.getOwnerComponent().getModel().oData;
var oFilteredModel = {};
for(var key in oModel) {
  if(oModel.hasOwnProperty(key)) {
     var obj = oModel[key];
     var startDate = obj.StartDate
     var finishDate = obj.FinishDate;
     //this is a general purpose filter, I need to know what you are sending when you send   //a date value to finishdate with no value   if(startDate  && finishDate) {
     oFilteredModel[key] = obj;
   }
 }
}var oNewModel = new JSONModel({WorkOrderDetailSet:oFilteredModel});
console.log(oNewModel);
var oCalendar = this.getView().byId("PC1");
oCalendar.setModel(oNewModel,"calendar_model");
                         oCalendar.bindAggregation("rows",{path:"calendar_model/>WorkOrderDetailSet"});

This is my view layer:

<PlanningCalendar id="PC1" startDate="{FinishDate}" rows="{path: 'calendar_model>/WorkOrderDetailSet'}" appointmentSelect="handleAppointmentSelect" rowSelectionChange="handleAppointmentSelect">

  <toolbarContent>

  <Title text="Work Orders Timeline" titleStyle="H4"/>

  </toolbarContent>

  <rows>

  <PlanningCalendarRow  title="{WorkorderNo}" text="{WorkorderText}" >

  <appointments>

  <u:CalendarAppointment startDate="{StartDate}" endDate="{FinishDate}">

  </u:CalendarAppointment>

  </appointments>

  </PlanningCalendarRow>

  </rows>

  </PlanningCalendar>

However, I get an error when executing this code that says:

Uncaught Error: Missing template or factory function for aggregation rows of Element sap.m.PlanningCalendar#__component0---worklist--PC1

I would ideally like to do the binding in the XML view itself but that does not seem to be possible. If that is not possible, I would like to bind the aggregation path in the view leaving the template to be bound in the xml view.

Accepted Solutions (0)

Answers (1)

Answers (1)

saivellanki
Active Contributor
0 Kudos

Hi Vamsi,

Actually, it should work when you just update the model, no need to bind rows again. Since, JSON is a two way model.

If you want to go ahead with bindAggregation method, then you can try something like this:


oCalendar.bindAggregation("rows", {path: "calendar_model/>WorkOrderDetailSet", template: oCalendar.getRows()[0].clone()});

Regards,

Sai.

Former Member
0 Kudos

Hi Sai,

I got a big fat error message that looked like this:

During a clone operation, a template was found that neither was marked with 'templateShareable:true' nor 'templateShareable:false'. The framework won't destroy the template. This could cause errors (e.g. duplicate IDs) or memory leaks (The template is used in aggregation 'appointments' of object '__row0').For more information, see documentation under 'Aggregation Binding'

In my controller, I added the templateShareable to the binding, something like this:

var oModel = this.getOwnerComponent().getModel().oData;

  var oFilteredModel = {

  WorkOrderDetailSet:[]

};

for(var key in oModel) {

  if(oModel.hasOwnProperty(key)) {

  var obj = oModel[key];

  var StartDate = obj.StartDate;

  var FinishDate = obj.FinishDate;

  var WorkorderNo = obj.WorkorderNo;

  var WorkorderText = obj.WorkorderText;

  //this is a general purpose filter, I need to know what you are sending when you send

  //a date value to finishdate with no value

  if(StartDate  && FinishDate) {

       oFilteredModel.WorkOrderDetailSet.push({

  confirmations:[

  {

  StartDate:StartDate,

  FinishDate:FinishDate

  }

  ],

  WorkorderNo:WorkorderNo,

  WorkorderText:WorkorderText

       });

    }

  }

}

var oNewModel = new JSONModel(oFilteredModel);

var oCalendar = this.getView().byId("PC1");

oCalendar.setModel(oNewModel,"calendar_model");

var oTemplate = oCalendar.getRows()[0].clone();

oCalendar.bindAggregation("rows", {

     path:"calendar_model/>WorkOrderDetailSet",

     template: oTemplate,

     templateShareable:false

});

I changed my data model to something that looks like this:

{

  WorkOrderDetailSet:[

  {

      WorkorderNo,

      WorkorderText,

      confirmations:[

        {

           StartDate,

           FinishDate

        }

       ]

    }

  ]

}


I added the confirmations to the appointments aggregation and the view looks like this:

<PlanningCalendar id="PC1" startDate="{FinishDate}" rows="{path: '/WorkOrderDetailSet'}" appointmentSelect="handleAppointmentSelect" rowSelectionChange="handleAppointmentSelect">

  <toolbarContent>

       <Title text="Work Orders Timeline" titleStyle="H4"/>

  </toolbarContent>

  <rows>

       <PlanningCalendarRow appointments="{confirmations}" title="{WorkorderNo}" text="{WorkorderText}" >

            <appointments>

                 <u:CalendarAppointment startDate="{StartDate}" endDate="{FinishDate}">

                 </u:CalendarAppointment>

            </appointments>

       </PlanningCalendarRow>

  </rows>

</PlanningCalendar>