4

I have created a responsive sap.m.table. But am not able to load values from the data Object. I want to laod the "subvariants" array of objects.Pls help

 summaryDetailData={"subvariants":[{"currentValue":"","Article":"1234567","question":"Carpet Installation type"},{"currentValue":"","question":"CarpetQuantity"},{"currentValue":"","Article":"1234568","question":"Underpad type"},{"currentValue":"","question":"UnderpadQuantity"},{"currentValue":false,"Article":"1234568","question":"Rapid Install"}]}



  var oTable = new sap.m.Table("idRandomDataTable", {
    headerToolbar: new sap.m.Toolbar({
    content: [
    new sap.m.Label({text: "Summary Data"}),
    new sap.m.ToolbarSpacer({}),
    new sap.m.Button("idPersonalizationButton", {
    icon: "sap-icon://person-placeholder"
    })]}),
     columns: summaryDetailData.cols.map(function (colname) {
        return new sap.m.Column({ header: new sap.m.Label({ text: colname })})
            })      
    });

    oTable.setModel(new sap.ui.model.json.JSONModel(summaryDetailData));
    oTable.bindAggregation("subvariants", "/subvariants", new sap.m.ColumnListItem({
        cells: oData.cols.map(function (colname) {
            return new sap.m.Label({ text: "{" + colname.toLowerCase() + "}" })
            })
        }));
0

1 Answer 1

9

The way you bind the model to the table is not completely correct. You have to use bindItems to dynamically bind the table rows (items) to a model. The columns aggregation is used to define the column layout of the table whereas the items aggregation is responsible for the table records.

In your case I would create the columns in the control definition and bind the items to the model with your own template.

This should do what you´ve expected (tested it):

var oTable = new sap.m.Table("idRandomDataTable", {
        headerToolbar : new sap.m.Toolbar({
            content : [ new sap.m.Label({
                text : "Summary Data"
            }), new sap.m.ToolbarSpacer({}), new sap.m.Button("idPersonalizationButton", {
                icon : "sap-icon://person-placeholder"
            }) ]
        }),
        columns : [ new sap.m.Column({
            width : "2em",
            header : new sap.m.Label({
                text : "Current Value"
            })
        }), new sap.m.Column({
            width : "2em",
            header : new sap.m.Label({
                text : "Article"
            })
        }), new sap.m.Column({
            width : "2em",
            header : new sap.m.Label({
                text : "Question"
            })
        }) ]
    });

    oTable.bindItems("/subvariants", new sap.m.ColumnListItem({
        cells : [ new sap.m.Text({
            text : "{currentValue}"
        }), new sap.m.Text({
            text : "{Article}"
        }), new sap.m.Text({
            text : "{question}",
        }), ]
    }));

    oTable.setModel(new sap.ui.model.json.JSONModel(summaryDetailData));

Hopefully this helps you!

1
  • Esp. Note the last row! You cannot bind against plain JSON data, you have to create a sap.ui.model.json.JSONModel from it first.
    – cschuff
    Jan 24, 2014 at 11:24

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.