-
Notifications
You must be signed in to change notification settings - Fork 139
Tree view #2277
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
base: main
Are you sure you want to change the base?
Tree view #2277
Changes from all commits
8e3d001
4ddf2bf
ffe9454
6438ed4
a84ad40
02221bf
6adf028
2488971
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||||||
|---|---|---|---|---|---|---|---|---|---|---|
|
|
@@ -745,9 +745,9 @@ Cache Control feature is currently supported on the Java runtime only. | |||||||||
|
|
||||||||||
| ## Hierarchical Tree Views | ||||||||||
|
|
||||||||||
| Recursive hierarchies are parent-child hierarchies, where each entity references its parent and through that defines the hierarchical structure. A common example is a company organization structure or HR reporting, where each employee entity references another employee as a direct report or manager. | ||||||||||
| Recursive hierarchies are parent-child hierarchies: each entity references its parent and through that defines the hierarchical structure. A common example is a company organization structure or HR reporting, where each employee entity references another employee as a direct report or manager. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Hierarchies are hierarchies :) may be
Suggested change
?
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
Contributor
Author
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. This section comes from the original tree view docu by the runtimes, haven't touched it. |
||||||||||
|
|
||||||||||
| A generic hierarchy implementation for hierarchies is available on all relational datases supported by the CAP runtimes. | ||||||||||
| A generic hierarchy implementation for hierarchies is available on all relational databases supported by the CAP runtimes. | ||||||||||
|
|
||||||||||
| ::: warning | ||||||||||
| On H2, only small hierarchies should be used for performance reasons. | ||||||||||
|
|
@@ -761,6 +761,7 @@ Let's assume we have the following domain model and its projection in a service: | |||||||||
| namespace my.bookshop; | ||||||||||
|
|
||||||||||
| entity Genres { //... | ||||||||||
| ID : UUID; | ||||||||||
| parent : Association to Genres; | ||||||||||
| } | ||||||||||
| ``` | ||||||||||
|
|
@@ -774,19 +775,67 @@ service AdminService { | |||||||||
| ``` | ||||||||||
| ::: | ||||||||||
|
|
||||||||||
| In this example, there is a managed to-one association `parent` that defines the parent-child hierarchy | ||||||||||
| based on a single key element. In such a situation you can define the Tree View via the annotation `@hierarchy`: | ||||||||||
|
|
||||||||||
| Annotate/extend the entity in the service as follows: | ||||||||||
| ```cds | ||||||||||
| annotate AdminService.Genres with @hierarchy : parent; | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| If the entity contains only one such association, you can even omit the value: | ||||||||||
|
|
||||||||||
| ```cds | ||||||||||
| annotate AdminService.Genres with @hierarchy; | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| Configure the TreeTable in UI5's _manifest.json_ file: | ||||||||||
|
|
||||||||||
| ```jsonc | ||||||||||
| "sap.ui5": { ... | ||||||||||
| "routing": { ... | ||||||||||
| "targets": { ... | ||||||||||
| "GenresList": { ... | ||||||||||
| "options": { | ||||||||||
| "settings": { ... | ||||||||||
| "controlConfiguration": { | ||||||||||
| "@com.sap.vocabularies.UI.v1.LineItem": { | ||||||||||
| "tableSettings": { | ||||||||||
| "hierarchyQualifier": "GenresHierarchy", // [!code focus] | ||||||||||
| "type": "TreeTable" // [!code focus] | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| > Note: construct the `hierarchyQualifier` with the following pattern: <br> | ||||||||||
| > `<entity name in service>Hierarchy` | ||||||||||
|
|
||||||||||
| You can now start the server with `cds watch` and see the hierarchical tree view in action in the [_Browse Genres_](http://localhost:4004/fiori-apps.html#Genres-display) app. | ||||||||||
|
|
||||||||||
|  {style="filter: drop-shadow(0 2px 5px rgba(0,0,0,.40));"} | ||||||||||
|
|
||||||||||
| The compiler automatically expands the shortcut annotation `@hierarchy` to the | ||||||||||
| following annotate and extend statements. | ||||||||||
|
Contributor
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
Suggested change
|
||||||||||
|
|
||||||||||
| ### Manual Approach | ||||||||||
|
|
||||||||||
| The following documents what happens behind the scenes, done by the compiler as described before. You can also use it, if you cannot use the `@hierarchy` annotation, for example, because you only have an unmanaged parent association. | ||||||||||
|
|
||||||||||
| ```cds | ||||||||||
| // declare a hierarchy with the qualifier "GenresHierarchy" | ||||||||||
| annotate AdminService.Genres with @Aggregation.RecursiveHierarchy #GenresHierarchy : { | ||||||||||
| annotate AdminService.Genres with @Aggregation.RecursiveHierarchy #GenresHierarchy: { | ||||||||||
| NodeProperty : ID, // identifies a node, usually the key | ||||||||||
| ParentNavigationProperty : parent // navigates to a node's parent | ||||||||||
| }; | ||||||||||
|
|
||||||||||
| extend AdminService.Genres with @( | ||||||||||
| // The computed properties expected by Fiori to be present in hierarchy entities | ||||||||||
| Hierarchy.RecursiveHierarchy #GenresHierarchy : { | ||||||||||
| Hierarchy.RecursiveHierarchy #GenresHierarchy: { | ||||||||||
| LimitedDescendantCount : LimitedDescendantCount, | ||||||||||
| DistanceFromRoot : DistanceFromRoot, | ||||||||||
| DrillState : DrillState, | ||||||||||
|
|
@@ -797,7 +846,7 @@ extend AdminService.Genres with @( | |||||||||
| 'LimitedDescendantCount', 'DistanceFromRoot', 'DrillState', 'LimitedRank' | ||||||||||
| ], | ||||||||||
| // Disallow sorting on these properties from Fiori UIs | ||||||||||
| Capabilities.SortRestrictions.NonSortableProperties : [ | ||||||||||
| Capabilities.SortRestrictions.NonSortableProperties: [ | ||||||||||
| 'LimitedDescendantCount', 'DistanceFromRoot', 'DrillState', 'LimitedRank' | ||||||||||
| ], | ||||||||||
| ) columns { // Ensure we can query these columns from the database | ||||||||||
|
|
@@ -811,31 +860,5 @@ extend AdminService.Genres with @( | |||||||||
| > Note: When naming the hierarchy qualifier, use the following pattern: <br> | ||||||||||
| > `<entity name in service>Hierarchy` | ||||||||||
|
|
||||||||||
| Configure the TreeTable in UI5's _manifest.json_ file: | ||||||||||
|
|
||||||||||
| ```jsonc | ||||||||||
| "sap.ui5": { ... | ||||||||||
| "routing": { ... | ||||||||||
| "targets": { ... | ||||||||||
| "GenresList": { ... | ||||||||||
| "options": { | ||||||||||
| "settings": { ... | ||||||||||
| "controlConfiguration": { | ||||||||||
| "@com.sap.vocabularies.UI.v1.LineItem": { | ||||||||||
| "tableSettings": { | ||||||||||
| "hierarchyQualifier": "GenresHierarchy", // [!code focus] | ||||||||||
| "type": "TreeTable" // [!code focus] | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| } | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| }, | ||||||||||
| ``` | ||||||||||
|
|
||||||||||
| > Note: use the `hierarchyQualifier` declared earlier | ||||||||||
|
|
||||||||||
| <div id="reserved-words" /> | ||||||||||
|
|
||||||||||
Uh oh!
There was an error while loading. Please reload this page.