Skip to Content
0

How to bind dynamic values on filter odata in xml format?

Feb 04, 2017 at 10:41 AM

1.2k

avatar image

Hi all,

I have a list and I need to load the list dynamically based on the filter value passed to it. I use XML view for coding. Here's is what I have tried.

View.xml:

<List id="Aprovalmat" items="{path: '/TRANS_MATSet',

filters : [

{path : 'Pa',operator : 'EQ',value1:'ALG1'},

{path : 'PfNum',operator : 'EQ',value1:'4045'},

{path : 'Psa',operator : 'EQ',value1:'AL01'} ] }">

<items>

<StandardListItem id="idtrmatrix" title="{Name}" info="{Designation}" />

</items> </List>

This works fine when the 'value1' field is static. But now, I need to pass dynamic values to the 'value1' field. I changed my code to the following:

View.xml:

<List id="Aprovalmat"></List>

Controller.js:

var list = sap.ui.getCore().byId("Aprovalmat");

var oItems = new sap.m.ObjectListItem({ title: "{Name}", number:"{Designation}", numberUnit:"", type:"Active" });

var oFilters = [ new sap.ui.model.Filter("Pa", sap.ui.model.FilterOperator.EQ, pacode),

new sap.ui.model.Filter("PfNum", sap.ui.model.FilterOperator.EQ, pfcode),

new sap.ui.model.Filter("Psa", sap.ui.model.FilterOperator.EQ, psacode)]; list.bindItems("/TRANS_MATSet",oItems,oFilters);

I face an issue binding the data to the list and I was not able to achieve it.

Can Someone help me with this?

Thanks & Regards,

Ramya

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

3 Answers

Best Answer
Jun Wu Feb 04, 2017 at 01:34 PM
1

you have to do it in the controller, not able to do it in xml binding

Show 3 Share
10 |10000 characters needed characters left characters exceeded

Yes I'm trying it in controller. But Still I am not able to achieve it.

0

var list = sap.ui.getCore().byId("Aprovalmat");

change to

var list = this.byId("Aprovalmat");

1

Thanks Jun Wu. Now it works like a charm.

0
Murali Lakshmanan Feb 04, 2017 at 01:53 PM
0

3rd argument in list.bidnItems() is sorters. Can you please try this way?

list.bindItems("/TRANS_MATSet",oItems, null, oFilters);
Show 1 Share
10 |10000 characters needed characters left characters exceeded

Hi Murali,

Thanks for your reply. I tried the following like you have said me. "list.bindItems("/TRANS_MATSet",oItems, null, oFilters);"

But I get an error:"cannot read property 'bindItems' of undefined.

How to solve this error?

0
Sai Vellanki Feb 06, 2017 at 04:54 AM
0

Hi Ramya,

Can you try something like below:

var list = sap.ui.getCore().byId("Aprovalmat");
var oItems = new sap.m.ObjectListItem({
    title: "{Name}",
    number: "{Designation}",
    numberUnit: "",
    type: "Active"
});
var oFilters = [new sap.ui.model.Filter("Pa", sap.ui.model.FilterOperator.EQ, pacode),
    new sap.ui.model.Filter("PfNum", sap.ui.model.FilterOperator.EQ, pfcode),
    new sap.ui.model.Filter("Psa", sap.ui.model.FilterOperator.EQ, psacode)
];
list.bindAggregation("items", {
    path: '/TRANS_MATSet',
    template: oItems,
    filters: oFilters
});

Regards,

Sai.

Share
10 |10000 characters needed characters left characters exceeded