cancel
Showing results for 
Search instead for 
Did you mean: 

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

former_member195820
Participant

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

Accepted Solutions (1)

Accepted Solutions (1)

junwu
Active Contributor

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

former_member195820
Participant
0 Kudos

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

junwu
Active Contributor

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

change to

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

former_member195820
Participant
0 Kudos

Thanks Jun Wu. Now it works like a charm.

Answers (2)

Answers (2)

saivellanki
Active Contributor

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.

Former Member
0 Kudos

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

list.bindItems("/TRANS_MATSet",oItems, null, oFilters);
former_member195820
Participant
0 Kudos

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?