How to Use Filters When Binding Items in an XML View in SAP UI5?

UI5

You can set filters to a binding in:

  1. a controller
  2. an XML view

Here is explained how to set a filter or multiple filters to binding in a controller.

Filter data in an XML view if the filtering is static. Therefore, set the filters in an XML view if the filtering stays the same from the start to the end of the application use.

For example, use an XML view if you have a list which item titles are supposed to be filtered permanently by the value foo.

Filter data in the controller of an XML view, if the filtering is dynamic. Therefore, set the filtering in the controller of an XML view if the filters get applied and removed during the application use.

For example, you need to use the controller if you have a list which is searchable for its item titles.

Set One or Multiple Filters in an XML view

For example, the request is to set two static filters to a list in an XML view:

  1. a filter for the title of a list item – value1
  2. a filter for the description of a list item – value2
<!-- in your XML view -->

...

<List
  id="list-id"
  items="{

    path: '/', 
    
    filters: [

      {
        path: 'value1', 
        operator: 'EQ', 
        value1: 'foo'
      },
      {
        path: 'value2', 
        operator: 'Contains', 
        value2: 'bar'
      }

    ]
  
  }">
  <items>
    
    <StandardListItem
      title="{value1}"
      description="{value2}"/>
  
  </items>
</List>

...

Change the Filter Condition in an XML view

By default, the filters are combined with an OR condition. See here for what a filters condition is and how to change a filter condition in a controller.

In an XML View is possible to change the default OR condition too. Just add the object property and with the value true to the respective filter to use the AND condition:

<!-- in your XML view -->

<List
  id="list-id"
  items="{

    path: '/', 
    
    filters: [

      {
        path: 'value1', 
        operator: 'EQ', 
        value1: 'foo',
        and: 'true'
      },
      {
        path: 'value2', 
        operator: 'Contains', 
        value2: 'bar'
      }

    ]
  
  }">
  <items>

    <StandardListItem
      title="{value1}"
      description="{value2}"/>

  </items>
</List>

...
No Comments

Get A COMPLETE SAP Modules Overview infographic (free)

Plus, receive for free SAP tips & insights and all future infographics that are only shared with the private newsletter subscribers. 

Complete SAP modules/components overview infographic.
Categories
Latest Poll
Essential Ressources

Leave a Reply

Your email address will not be published. Required fields are marked *

Fill out this field
Fill out this field
Please enter a valid email address.

Menu