Search code examples
bindingsapui5sap-fiori

How to bind a model to a table in SAPUI5


im trying to bind an entitySet from a oData-Service to a list. My code looks like this:

var list = oView.byId("list");
    var requestModel = new sap.ui.model.json.JSONModel()
    .attachRequestCompleted(function(data) {
        var model = new sap.ui.model.json.JSONModel();
        model.setData(data.getSource());
        list.setModel(model);
    });

requestModel.loadData("/sap/opu/odata/sap/XXX_SRV/detailSet?$filter=XXX eq 'XXX'");

My service returns a array of detail-Objects as expected but i can't seem to find a way to bind them to the list. Thanks


Solution

  • I finally found a solution:

    At first i had to create a dummy Path in my list like this:

    <Table class="sapUiResponsiveMargin" items="{/dummy}" id="table" width="auto">
    

    When you can bind the url directly to the table:

        var url = "/XXX?$filter=XXX eq '" + XXX + "'";
        var table = oView.byId("table");
        table.bindItems({
            path: url,
            template: table.getBindingInfo("items").template
        });