Search code examples
filterodatagroupingsapui5

filter grouping in sapui5


i got a very interesting bug, when i apply filters with different variables, the filtering works fine, but if i use one filter variable for example id ne 1 or id ne 2 and so on, the filters are not applied, because the odata doesnt seems to understand grouping of filters, the sapui5 automatically group them like (id ne 1 or id ne 2) so it doesnt work, but if i use filters like this: id ne 1 and year ne 2016 and scenario eq 2 without grouping, then this type of filter works fine, checked everything from the applied urls from developer's tool(network), the filters are applied. it seems that this sap odata doesnt understand the filter grouping, because the version can be old, or smth like this... also tried to define filter's parameter like: and: true, so that all filters applied through not OR but with AND operator, didnt help... So what can be the solution to solve this kind of bug or problem?!

thank you all for the help!


Solution

  • This is the way to concatenates filters by hand. So you can control the grouping manually.

    var filter1 = new sap.ui.model.Filter("id","NE", 1);
    var filter2 = new sap.ui.model.Filter("id","NE", 2);
    var andFilter = new sap.ui.model.Filter([filter1 ,filter2 ], true);
    var orFilter  = new sap.ui.model.Filter([filter1 ,filter2 ], false);
    

    Filter documentation