Skip to Content
0

SAPUI5 list items not updated

Jan 24, 2017 at 07:35 PM

449

avatar image
Former Member

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

10 |10000 characters needed characters left characters exceeded
* Please Login or Register to Answer, Follow or Comment.

2 Answers

Best Answer
VIPLOVE KHUSHALANI Jan 25, 2017 at 06:10 AM
0

Hi Tim Krause ,

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

Thanks

Viplove

Show 6 Share
10 |10000 characters needed characters left characters exceeded
Former Member

Hi,

this is the part where I bind the data to the list called master2List:

Br,

Tim

//Updatelist binding
this.getView().byId("master2List").getBinding("items").filter(filters);
0

Hi ,

Actually here you are just applying filters to your binding. Where are you doing the initial binding of the master2List? Setting the model to the list which has the initial data without filters.

thanks

Viplove

1
Former Member
VIPLOVE KHUSHALANI

Hi,

you are right, this is the problem.

this.oModel= sap.ui.getCore().getModel("myModel");
this.getView().setModel(this.oModel);
var searchString = this.oModel.getProperty("/soldTo");

Here, I am setting the model to myModel which is just for receiving the property "/soldTo" from myModel coming from master1. js

this.myModel = new sap.ui.model.json.JSONModel();

When I leave this part out in master2.js and instead just put a value like this for searchString:

/*var that = this;
this.oModel= sap.ui.getCore().getModel("myModel");
this.getView().setModel(this.oModel);
var searchString = this.oModel.getProperty("/soldTo");*/
var searchString = "3100000000";

Then the binding is updated correctly.

this.getView().byId("master2List").getBinding("items").filter(filters,sap.ui.model.FilterType.Control);

How can I set the core model in the master2.js after I received the /soldTo value? So I need to reverse this part:

/*var that = this;
this.oModel= sap.ui.getCore().getModel("myModel");
this.getView().setModel(this.oModel);
var searchString = this.oModel.getProperty("/soldTo");*/

Thanks for your help!

0

Hi Tim ,

Actually in master1.js why you are setting just soldTo property to the master model.Just to access that on the master2.js ??

If that's the case than instead of setting that to master model why can't you send search string when you navigate from master1 to master2

you can do this as below :

this code needs to be place on the select event of the selection field in the master1.js

var soldTo = this.getView().byId("SoldToInput").getValue();

this.getRouter().navTo("<master2 view name>",{

sString: soldTo

});

And to read the search string on the master2.js controller,you need to attach an event on the onInit of the controller like below :

onInit:function(){

var oRouter =this.getRouter();

oRouter.getRoute("<master2 view name>").attachMatched(this._onRouteMatched,this)

},

_onRouteMatched :function(oEvent){var oArgs

oArgs = oEvent.getParameter("arguments");

var searchString = oArgs.sString;

// here you can apply filters to the binding

}

thanks

Viplove

0
Former Member
VIPLOVE KHUSHALANI

Hi Viplove,

maybe you can help me still with one more thing, passing the values to master2 is fine now, thanks to you!

When I want to define the filters now, I have all together 3 filter fields, in my example I fill 2 fields (soldTo and orderNo) and press search. My code in the master2. js is like this:

// Set filter values
var filters = [];
// Sold to party
var soldTo = this.getView().byId("SoldToInput").getValue();
if (soldTo && soldTo.length > 0) {
filters = [ new sap.ui.model.Filter("Kunnr",
sap.ui.model.FilterOperator.Contains, soldTo) ];
}
// Order number
var orderNo = this.getView().byId("OrderNoInput").getValue();
if (orderNo && orderNo.length > 0) {
filters = [ new sap.ui.model.Filter("Vbeln",
sap.ui.model.FilterOperator.Contains, orderNo) ];
}

The problem is now that it only puts one value to the filters, not the two. I need to fill the filter one bye one, because it could be that only 1 field is filled and the others are empty, so I need to check first if there is a value entered and then put it to the filters. Any idea how to solve this?

Thanks,

Tim

0

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

1
Antonette Venter Jan 25, 2017 at 09:28 AM
0

Hello Tim

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

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

Hope this helps

Antonette

Share
10 |10000 characters needed characters left characters exceeded