Steve
Steve

Reputation: 11

Binding/Displaying OData data in a sap.m.Table control

I'm running into issue binding OData in a table control and I'm hoping one of you experts can spare a millisecond to tell me where I'm screwing up.

I can get the OData info from the backend server - step one is I just want to display it in a table with columns and step two is to present users with a segmented button to enable/disable processing of a countries data. Lets just get the data displayed now.

Here is the OData that is returned from the backed backend odata

Here is my createContent code - I want to do it in JavaScript:

        var oTable = new Table({
            height: '100%',
            firstVisibleRow: 0,
            visibleRowCountMode: sap.ui.table.VisibleRowCountMode.Auto,
            selectionMode: sap.ui.table.SelectionMode.None,
            selectionBehavior: sap.ui.table.SelectionBehavior.RowOnly
        }).addStyleClass('suggCompTableStyle');

        var oColName = new sap.ui.table.Column().setLabel('{i18n>txt_countryName}').bindElement("/data>LANDX");
        oTable.addColumn(oColName);

        var oModel = sap.ui.getCore().getModel();
        oModel.callFunction("/getCountryActiveList", 
                            "GET", 
                            {SPRAS: 'E'}, 
                            null, 
                            function(oData, oResponse)
                                { oTable.setModel( new sap.ui.model.json.JSONModel({data : oData.results}));
                                  oTable.bindRows("/data");
                                  alert("ok"); },
                            function(oError) {alert("err"); });
        /* eslint-enable no-alert */
        oTable.placeAt("content");

        var oPage = new sap.m.Page({
            title: "{i18n>title}",
            content: [
                oTable
            ]
        });

        var app = new sap.m.App("myApp", {
            initialPage: "oPage"
        });
        app.addPage(oPage);
        return app;
    }/* end createContent function */

My table is created with the correct number of rows but not displaying the column data. I guess I'm confused on how to bind the column data?

Thanks for the assistance. Steve

Upvotes: 0

Views: 2404

Answers (1)

Jorge Martins
Jorge Martins

Reputation: 321

The issue is in your binding oTable.bindRows("/data");.

The bindRows method is expecting a row template control of the type sap.ui.table.Row.

You can look into https://sapui5.hana.ondemand.com/#/api/sap.ui.base.ManagedObject/methods/bindAggregation for more information. The bindRows method expects an input parameter equal to the oBindingInfo of the bindAggregation method from the link I above.

Upvotes: 0

Related Questions