Skip to Content

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

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

Add comment
10|10000 characters needed characters exceeded

  • Get RSS Feed

3 Answers

  • Best Answer
    Feb 04, 2017 at 01:34 PM

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

    Add comment
    10|10000 characters needed characters exceeded

  • avatar image
    Former Member
    Feb 04, 2017 at 01:53 PM

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

    list.bindItems("/TRANS_MATSet",oItems, null, oFilters);
    Add comment
    10|10000 characters needed 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?

  • Feb 06, 2017 at 04:54 AM

    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.

    Add comment
    10|10000 characters needed characters exceeded