Skip to content

Commit 0fdb2e7

Browse files
committed
doc: add scroll to item example and update article
1 parent 659713e commit 0fdb2e7

File tree

1 file changed

+6
-25
lines changed

1 file changed

+6
-25
lines changed

articles/components/tree-grid/index.adoc

Lines changed: 6 additions & 25 deletions
Original file line numberDiff line numberDiff line change
@@ -144,40 +144,21 @@ include::{root}/src/main/java/com/vaadin/demo/component/treegrid/TreeGridScrollT
144144
----
145145
--
146146

147-
`TreeDataProvider` supports this feature out of the box. For other data providers, you will need to implement [methodname]#getParent(T item)# and [methodname]#getItemIndex(T item, HierarchicalQuery query)#.
148-
149-
=== Scrolling to an Item by Path
150-
151-
To use this feature, you need to specify the path of the item you want to view. The scroll position of the grid is adjusted to bring that item into view.
152-
153-
In contrast to scrolling to an item, possible collapsed parents of the item do not expand before scrolling.
154-
155-
If the item has collapsed parents, they expand before scrolling to the item.
156-
157-
[.example]
158-
--
159-
[source,typescript]
160-
----
161-
include::{root}/frontend/demo/component/tree-grid/tree-grid-imports.ts[preimport,hidden]
162-
----
163-
164-
[source,java]
165-
----
166-
include::{root}/src/main/java/com/vaadin/demo/component/treegrid/TreeGridScrollToItem.java[render,tags=snippet,indent=0]
167-
----
168-
--
169-
170147
`TreeDataProvider` supports this feature out of the box. For other data providers, you need to override and implement the following methods of [classname]`HierarchicalDataProvider`:
171148

172149
- [methodname]`getParent(T item)`
173150
- [methodname]`getItemIndex(T item, HierarchicalQuery query)`
174151

175152
=== Scrolling to an Item by Path
176-
177-
You can also scroll to an item by providing its hierarchical path – an array of indexes where each index refers to a child of the item at the previous index. For example, to scroll to the second child-row (index 1) of the third root-level row (index 2), you would provide the path 2, 1.
153+
You can also scroll to an item by providing its hierarchical path – an array of indexes where each index refers to a child of the item at the previous index.
178154

179155
Scrolling continues until it reaches the last index in the array or encounters a collapsed item.
180156

157+
With multiple levels of hierarchy, the path depends on the hierarchy format of the data provider.
158+
159+
- If the data provider uses nested hierarchy format, you need to specify the row index for each level, separately. For example, to scroll to the second child-row (index 1) of the third root-level row (index 2), you would provide the indexes 2, 1.
160+
- If the data provider uses flat hierarchy format, you need to specify the flat index of the item. The flat index only takes reachable items into account. Therefore, in order to reach the children of collapsed items, you need to expand them first. For example, to scroll to the second child-row (index 1) of the third root-level row (index 2) assuming only the ancestors of the item are expanded, you would provide the flat index 4.
161+
181162
[.example]
182163
--
183164
ifdef::lit[]

0 commit comments

Comments
 (0)