cancel
Showing results for 
Search instead for 
Did you mean: 

SAPUI5 - TreeTable

Former Member
0 Kudos

Hey,

I can't get a herarchy from my oData. What exactly did I do wrong?

<mvc:View 
controllerName="TreeTable2.controller.View" 
xmlns="sap.ui.table"
xmlns:m="sap.m"
xmlns:mvc="sap.ui.core.mvc">
 <TreeTable
        id="myTreeTable"
        selectionMode="Single"
        enableColumnReordering="false"
        expandFirstLevel="false"
        rows="{
            parameters : {
                countMode: 'Inline',
                numberOfExpandedLevels: 1,
                treeAnnotationProperties : {
                    hierarchyLevelFor : 'HierarchyLevel',
                    hierarchyNodeFor : 'NodeID',
                    hierarchyParentNodeFor : 'ParentNodeID',
                    hierarchyDrillStateFor : 'HierarchyDrillState'
                }
            }
        }">
        <columns>
            <Column label="Description">
                <template>
                    <m:Text text="{Description}" wrapping="false" />
                </template>
            </Column>
            <Column label="HierarchyLevel">
                <template>
                    <m:Text text="{HierarchyLevel}" wrapping="false" />
                </template>
            </Column>
            <Column label="NodeID">
                <template>
                    <m:Text text="{NodeID}" wrapping="false" />
                </template>
            </Column>
            <Column label="ParentNodeID">
                <template>
                    <m:Text text="{ParentNodeID}" wrapping="false" />
                </template>
            </Column>
            <Column label="HierarchyDrillState">
                <template>
                    <m:Text text="{HierarchyDrillState}" wrapping="false" />
                </template>
            </Column>
        </columns>
    </TreeTable>
</mvc:View>
onInit: function () {
	var oTreeTable = this.getView().byId("myTreeTable");
	oTreeTable.bindRows({
	path: '/ZC_EMPLOYEE_TEST'
	});
}<br>

regards

Tim

junwu
Active Contributor
0 Kudos

can you post your annotation regarding the hierarchy? it is in your metadata tile.

Former Member
0 Kudos

The problem is, I don't see any annotations there regarding a hierarchy. The hierarchy is build with CDS:

define hierarchy ZHI_EMPLOYEEHIER

as parent child hierarchy(

source ZHI_EMPLOYEERELATION

child to parent association _Manager

start where

Manager is initial

siblings order by

Employee

orphans root

)

{

@ObjectModel.foreignKey.association: '_Employee'

key Employee,

_Employee,

Manager,

_Manager,

$node.node_id as Child_ID,

$node.parent_id as Parent_IDs,

$node.hierarchy_is_orphan as HierarchyIsOrphan,

$node.hierarchy_level as HierarchyLevel,

$node.hierarchy_rank as HierarchyRank,

$node.hierarchy_parent_rank as HierarchyParentRank,

$node.hierarchy_tree_size as HierarchyTreeSize,

$node.hierarchy_is_cycle as HierarchyIsCycle

}

Former Member
0 Kudos

The oData is built with Service-Definition and Service-Bindings

junwu
Active Contributor
0 Kudos

I think you need to have hierarchy related annotation in your metadata, if not, how can the hierarchy to be rendered by frontend?

Former Member
0 Kudos

Really? 😉

Accepted Solutions (0)

Answers (1)

Answers (1)

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Tim,

It seems to me like you are trying to bind your table to 2 different entity set, once onInit and once in the view itself? Make sure you are binding the correct entity set - you shouldn't need to do anything for this onInit at all.

Besides, I do see a hierarchy rendered in your screenshot, it just isn't expanded. If you want to show the nodes as initially expanded, you can pass below parameter to your row binding in the XML view.

numberOfExpandedLevels: 1

If there was no hierarchy, the framework would not even render the arrow to collapse.

Or are the fields inside empty? If that is the case, you might need to make some adjustments to your OData Service or alternatively bind the table to a JSON Model with deep structure instead.

Former Member
0 Kudos

Thanks for the hint Leoni, I have edit my Code above.

But I get some Errors now:

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Tim,

According to the first error - In your view and inside the rows property or your table, you should still provide the binding path. I beleive you had this before..

 rows="{
            path : '/ZC_EMPLOYEE_TEST',
parameters : { countMode: 'Inline', numberOfExpandedLevels: 1, ... }"
Former Member
0 Kudos

Ah okay, I understand. Remains this error:

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Tim,

I think your view should still be rendering despite this error, is it not?

Please compare with this sample for Basic OData Tree Table binding, like you are attempting, and see if you can identify any differences. Or if you can try with oData Annotations like here.

Former Member
0 Kudos

Hey Leoni,

yes the view is still rendering. My app is already based on the example you mentioned. I have now gone through everything again step by step and with the mock data from the example it works, just not with the data from the oData. So I would actually say it is because of the oData or the CDS-Views...

The CDS views I built for this example are based on the example in the book "Core Data Services für ABAP". Now the basic question is how must the CDS view be structured? I have built the example according to the method of CDS hierarchies. However, there is a basic distinction between "annotation-based hierarchies" and "CDS hierarchies". Is it at all possible to build a SAPUI5 or Fiori Elements app on the basis of CDS hierarchies or must annotation-based hierarchies be used in principle?

regards Tim

Former Member
0 Kudos

Hey Leonie,

do you have a solution?

regards Tim

leonikussmaul
Product and Topic Expert
Product and Topic Expert
0 Kudos

Hi Tim,

If the view is still rendering, what exactly is the issue aside from the error in the console?

Former Member
0 Kudos

Hey Leonie,

the view is still rendering and the error in the console is: