0

I retrieve from server a json with two field: an array of the structure (columns list) and an array with the effective data. I see this example https://openui5.hana.ondemand.com/explored.html#/sample/sap.m.sample.Table/code and here i can mapping (data-binding) dinamically the data in the table but I have to manually enter the columns!!!!

How can I mappin automatically also the structure (cols) of my table?

Now I use a code in the controller that insert a list of cols and the rows:

for(var i=0; i<tableResult.getModel().getProperty("/cols").length; i++){

                tableResult.addColumn(new sap.m.Column(tableResult.getModel().getProperty("/cols")[i], { header: new sap.m.Label({design:"Bold" , text: tableResult.getModel().getProperty("/cols")[i] })}));   



        }



tableResult.bindAggregation("items", "/items", new sap.m.ColumnListItem({
    cells: tableResult.getModel().getProperty("/cols").map(function (colname) {
        return new sap.m.Label({ text: "{" + colname + "}" });
    }),
    type:myType
}));

But I do not like this solution

padibro
  • 1,324
  • 10
  • 56
  • 95
  • Hi bradipo, your solution i guess is the only solution. – Haojie Jul 31 '14 at 13:00
  • There's a better, cleaner way: I had this issue a while ago too, see https://stackoverflow.com/questions/21731176/dynamic-binding-of-table-column-and-rows Both solutions provided by @Jasper_07 work like a charm – Qualiture Jul 31 '14 at 20:29

0 Answers0