openui5 icon indicating copy to clipboard operation
openui5 copied to clipboard

How to filter "or" filter in xml

Open FnEsc opened this issue 5 years ago • 1 comments

Version

Version 1.84.0

Question

How to filter "or" filter in xml?

Description

In "sap.m.Table", I need to filter the odata with two filters.

But now, I can not filter odata with "or".

<Table class="sapUiResponsiveMargin" id="tableProcessed" width="auto" items="{
    path: '/ZEKKOCollection',
    sorter: {
        path: 'Ebeln',
        descending: true
    },
    filters: [{
      path: 'Frgke',
      operator: 'EQ',
      value1: 'R'
    },
    {
      path: 'Procstat',
      operator: 'EQ',
      value1: '08'
    }]
}" growing="true" growingScrollToLoad="true" headerText="Items" mode="MultiSelect" >

In this way, I found the request is to:

ZEKKOCollection?$skip=0&$top=20&$orderby=Ebeln%20desc&$filter=Frgke%20eq%20%27R%27%20and%20Procstat%20eq%20%2708%27

So, actually it works for filters with "and" instead of "or".

How can I access the odata with url:

ZEKKOCollection?$skip=0&$top=20&$orderby=Ebeln%20desc&$filter=Frgke%20eq%20%27R%27%20or%20Procstat%20eq%20%2708%27

FnEsc avatar Dec 23 '20 03:12 FnEsc

You can create a Filter object also with a filters array and a boolean flag and. That will combine the filters either with AND (true) or OR (false).

<Table class="sapUiResponsiveMargin" id="tableProcessed" width="auto" items="{
    path: '/ZEKKOCollection',
    sorter: {
        path: 'Ebeln',
        descending: true
    },
    filters: {
        filters: [{
          path: 'Frgke',
          operator: 'EQ',
          value1: 'R'
        },
        {
          path: 'Procstat',
          operator: 'EQ',
          value1: '08'
        }],
        and: false // default, can be omitted
    }
}" growing="true" growingScrollToLoad="true" headerText="Items" mode="MultiSelect" >

For models that use the FilterProcessor, the default behavior for a simple array of filters is something in between: filters for different paths are combined with AND, filters for the same path are combined with OR.

codeworrior avatar Dec 23 '20 06:12 codeworrior