0

I'm new to SAPUI5 component.

Is there a way to apply $filter to sap.m.Tree? It seems weird to me.

I'm currently using $filter options to limit the data from back-end (by using WHERE clause, came from $filter option), so I have to $filter to pass my parameter.

My controller :

this.oCharTable = this.getView().byId("CharTree")

var aFilterChar = new Filter("Matnr", FilterOperator.EQ , filter_base[2])

this.oCharTable.bindElement({
    path:  "/AUSP_ENTITY",
    model: "AUSP_DATA",
    filters: [aFilterChar],
    parameters: {
        NumberOfExpandedLevels : 2
    }
});

and It's $batch payload :

GET AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27&$skip=0&$top=100 HTTP/1.1
sap-cancel-on-close: true
  • Does this answer your question? [How to search for all nodes in a sap.m.Tree?](https://stackoverflow.com/questions/48888628/how-to-search-for-all-nodes-in-a-sap-m-tree) – Boghyon Hoffmann Jun 18 '21 at 12:20

2 Answers2

0

It depends on your data source:

  • if you have a odata v2, you can't filter on children. This is simply not supported by v2
  • if you have a odata v4, this is not supported by tree-binding. Good news, it on the roadmap https://github.com/SAP/openui5/issues/2728
  • if you preload all data an put it in a json model. You could filter as you like with vanilla js

Based on the given answer. You could just ignore v2 specification and filter in the backend as you want with any passed filter.

Benedikt Kromer
  • 711
  • 6
  • 22
0

Oh, I think I found the solution - the problem is on backend!

Thanks to this answer, Using Suspend - Resume makes me send right GET request, like

../AUSP_ENTITY?$filter=HierarchyLevel%20eq%20%270%27%20and%20(Matnr%20eq%20%27SomeKindofMaterialHere%27)&$skip=0&$top=100

I changed my backend to select right values, and returning value to frontend.

  • For future leaders, who might read my question, I changed my backend to take not only take 1 option (this one, might be Matnr), but also take 'HierarchyLevel', which have to be taken care of.

In detail - I using $filter parameters to get data from CDS View, which can reduce the select result to resonable level.

so I redefine DPC_EXT Class, split up my $filter input, and put it into my parameter, and put result into result table.

TL;dr : If you using $filter on Tree View : check the 'return' backend. It might be problem in there.

  • It's weird. When I removed suspend - resume, It doesn't send filtered GET request to backend. It just send 'HierarchyLevel' , which are used to find child. But If I put resume in it, It works.. I really don't know how it works, but it's working.. – Park Chan Seul Jun 21 '21 at 06:43