cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 Treetable ParentNodeID null

Former Member
0 Kudos

I want to use a treetable with oData Model. I started from this example.

In the example, the parent nodes have ParentNodeID: null, because they have no parent. The subnodes have ParentNodeID: 1 (or 2 or 3 or ...), because they have a parent.

In my data, the parentNodeID for parents is 0 (instead of null). It is coming from the gateway in this way. Even if I keep in my gatewaycode the parentNodeID empty for parents, it is set to 0. I think because it is a number and the default initial value for numbers is 0.

My Treetable isn't working now. I suppose it is looking for a node with ID 0 to use as parent but of course that does not exist.

How can I set the parentNodeID for parent nodes to null (not 0)?

Or should a Treetable also work with parentNodeID for parents is 0? Then the reason why my Treetable is not working will be something else.

Accepted Solutions (0)

Answers (2)

Answers (2)

0 Kudos

For those with the same issue described above, here goes a suggestion:

1. Perform a read (GET) function on the OData entity set which provides the values for ParentNodeID, NodeID and so on via UI5;

2. Loop through the results array (for or forEach) and implement an IF statement that compares the ParentNodeID property against 0; overwrite the property to null if that's the case;

3. Populate a JSON Model with the results - you'll have overwritten the 0s for nulls in all ParentNodeID occurrences, where applicable;

3. Call the bindRows method of the TreeTable, this time using your JSON Model. Make sure you mention the model name and that in the pattern of the bindColumns method you also provide the model name to the bound property.

iftah_peretz
Active Contributor
0 Kudos

Hi,

I will assume that you are using the SAP Gateway service Builder (SEGW) as your OData provider.

I have 2 questions, the first, is the 'Edm Type' of the field 'ParentNodeID' defined as "Edm.Int32" (in your properties of the entity type of the data model)? And the second, did you check the box 'Nullable' for that same field?

Do that and don't pass anything to the 'ParentNodeID'.

shubhangi95
Explorer
0 Kudos

Hello Iftah,

I am facing the same issue and I tried your solution. My 'ParentNodeID' is defined as "Edm.Int32" in SEGW and I have marked it as 'Nullable'. I am passing nothing to the 'ParentNodeID from the backend. But it is still taking 0 as the default value in the frontend because of which the Tree table is not working properly. Can you suggest some other solution?