Skip to Content
avatar image
Former Member

SAPUI5 list items not updated

Hi,

I am using master-master-detail app. I have a selection field on the first master screen and then from there I want to navigate to master2, set the filter with the value from the selection field in master1 screen, get the data from the backend and display it in the master2 screen.

My code in master1.js

var json = {};
json.soldTo = this.getView().byId("SoldToInput").getValue();
this.myModel.setData(json);
sap.ui.getCore().setModel(this.myModel, "myModel");

My code in master2.js:

var that = this;
this.oModel= sap.ui.getCore().getModel("myModel");
this.getView().setModel(this.oModel);
var searchString = this.oModel.getProperty("/soldTo");
// Sold to Filter set
var filters = [];
if (searchString && searchString.length > 0) {
filters = [ new sap.ui.model.Filter("Kunnr",
sap.ui.model.FilterOperator.Contains, searchString) ];
}
// Update list binding
this.getView().byId("master2List").getBinding("items").filter(filters);

And the master2.xml using master2List

     <List id="master2List" items="{/SalesOrderHdrSet}" mode="{device>/listMode}"  select="onSelect"
        growing="true" growingScrollToLoad="true" visible="true" >

The problem is, I can see the selection field value in master2 controller and the filter is set ok but the list binding is not updated, so data is not retrieved from the backend. Is it to do with the myModel I set? This myModel I am using just to get the value from master1 to master2.

Any help is appreciated.

Thanks,

Tim

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

2 Answers

  • Best Answer
    Jan 25, 2017 at 06:10 AM

    Hi Tim Krause ,

    Where are you attaching data to the List in master2 controller.js ?

    Thanks

    Viplove

    Add comment
    10|10000 characters needed characters exceeded

    • Hi Tim ,

      var filters = [];

      means variable filter is an array . So instead of assigning like filters = [ new sap.ui.model.Filter("Vbeln",sap.ui.model.FilterOperator.Contains, orderNo) ] as this will overwrite you previous value in filter, you should use push() method of array.

      filters = [ new sap.ui.model.Filter("Vbeln",sap.ui.model.FilterOperator.Contains, orderNo) ] // wrong way

      filters.push(new sap.ui.model.Filter("Vbeln",sap.ui.model.FilterOperator.Contains, orderNo));//correct way

      thanks

      Viplove

  • Jan 25, 2017 at 09:28 AM

    Hello Tim

    Have you tried refreshing the model and bindings after the filtering?

    this.getView().getModel("myModel").refresh();

    Hope this helps

    Antonette

    Add comment
    10|10000 characters needed characters exceeded