Eli
Eli

Reputation: 626

Sapui5: How can i retrieve oData dynamically using manifest.json

I have configured manifest.json & neo-app.json

    "dataSources": {
        ,"news": {
            "uri": "/destinations/int_news/sap/opu/odata/sap/XKDNK/",
            "type": "OData",
            "settings": {
                "odataVersion": "2.0"
            }
        }
    },
    "models": {
          "news": {
            "dataSource": "news"
          }
    }

Fetching the oData in my controller:

var oModel =  this.getModel("news");
   oModel.read("/planSet", {
    success: function(data){
        debugger;
    }
}); 

But its fetching all the data more then 1000 rows, I need to add a filter to the query.

I have managed to add filter only on direct URL:

$filter=SystemId eq \"SKYPE\"

But How can I add in JavaScript the filter dynamically without fetching all the data? For example:

var oModel =  this.getModel("news");

oModel.read("/planSet?$filter" + <MY_CUSTOM_DATA_FILTER>, {
    success: function(data){
       debugger;
    }
}); 

Upvotes: 0

Views: 3185

Answers (1)

Vivek Kumar
Vivek Kumar

Reputation: 66

Try to create a filter object where you pass your filter parameters and use this filter object as parameter in read call. like below

var oModel =  this.getModel("news"),
    sfilterVal = "SKYPE",
    aFilters = [];


        if (sfilterVal) {
            aFilters.push(new sap.ui.model.Filter("SystemId", sap.ui.model.FilterOperator.EQ, sfilterVal));
        }

        oModel.read("/planSet", {
            filters: aFilters,
            success: function(data){
                debugger;
            }
        });

Upvotes: 1

Related Questions