0

Excuse the confusing language but hopefully this makes sense: (see code for more clear explanation)

I have a requirement to display a list of "spare parts" in an sap.m.Table but there is the ability if one of these "spare parts" has a related "spare part" (e.g. A heavy duty version, a light version, etc) , that you can click a button on the row and display these related "spare parts" by inserting them immediately below the "spare part" in question.

While I can get the sap.m.Table doing what I want to do, I would like to take advantage of templates and binding to create a temporary sap.m.Table; bind it to the relationship that returns these alternate spare parts; and reuse the template for a row to give me an array of ColumnListItems which I can insert into the Table at the right place.

Unfortunately, doing this, a sap.m.Table has a feature that if it is not displayed, it doesn't actually make the Odata call and leverage the template function.

To explain possibly much clearer, refer to this jsbin: http://jsbin.com/sihofu/4/edit?html,js,output

Any better ideas on how to generate template output for a binding without using a sap.m.Table; or alternative, getting the sap.m.Table to make the call without placing it on the screen visible (temporarily)?

The specific code to look at is as follows:

var oTable2 = new sap.m.Table();
oTable2.attachUpdateFinished(function() { 
  console.log("But this one doesn't");
  // What I'm trying to do here is insert these entries below Key 1
});

oTable2.bindAggregation("items", {
  path: "/ExampleSecondaryValues",
  template: oTemplate,

  }); 

Thanks, Matt

1 Answer 1

0

Back from Holidays now and solved this problem with a bit of brute force by simply enhancing/extending the sap.m.table control slightly.

The problem was if the control was invisible, nothing was rendered, and some optimisation within UI5 core means that in the case nothing is rendered, the AfterRender event is not called on the control and this event is what fires the UpdateFinished event.

I won't debate whether that optimisation is appropriate or not, but to fix this I simply extended the table control with a new control which looks like as follows:

sap.m.Table.extend("my.InvisibleTable", { 
    renderer: function(oRm, oControl) { 
      oRm.write("<span"); 
      oRm.writeControlData(oControl);
      oRm.write("></span>");
    }
});

e.g. Simply always rendering something in the render function, causes the AfterRender event to be called; which in turns allows the sap.m.Table to fire the UpdateFinished event which allows me to then safely get the rendered template items to insert in my visible table.

Would love to know a much better way of doing this (possibly using the template control or similar), but this works okay to solve the problem.

Cheers, Matt

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.