Open mcfar opened 5 years ago
Any update on this?
I have a use case where a treegrid will be regularly updated with changes to data in the backend. Items being added or removed by other user sessions will necessitate refreshAll()
being called to remain up to date. Each update resulting in the scroll bar resetting to the top is blocking progress as it results in poor user experience.
We have the same issue. The reason seems to be, that the initial scroll height is not calculated based on all potentially available rows, but the root rows only.
One workaround could be to extend the hierarchical data provider api to allow the dev to set the expected amount of total rows parallel to the root rows. Based on this the grid can precalculate its expected scroll height. Hoever this value should not have the "last word", i.e., when the resulting size is more the three grid scroll height should grow as needed (as it is now already the case).
e.g.
public interface HierarchicalDataProvider<T, F> extends DataProvider<T, F> {
/**
* Returns the expected amount of total rows (root rows plus all child rows). This value is taken to precalculate the
* expected scroll height of the using component (e. g. a tree grid).
* <p/>
* Default calls size().
* @return total amount of rows to be expected
*/
default int totalSize(Query<T, F> query) {
return size(query);
}
}
I documented workaround here: https://github.com/vaadin/flow-components/issues/6307#issuecomment-2122250952
The workaround is unfortunately not suitable for all situations. A large TG with expanded rows has a much higher refresh time using the workaround (refreshAll ~5s, workaround ~35s).
The workaround doesn't work for root items being added or removed. They do not appear in the grid, although they are being listed in the root items when calling getRootItems()
.
If you select a row in a tree grid and it is outside the viewport, and then call a refreshAll() on it, it scrolls to top of the grid. If you have a row selected and call a refresh, I'd expect it to retain the selected row in the viewPort. We have a use case where the user can change the display value for the hierarchy column. When the new caption is changed, the tree grid calls a refreshAll() so the new caption will be used.
Example `public class TreeGridMainView extends VerticalLayout { private static final String NAME = "name"; private static final String DESCRIPTION = "description"; private TreeDataProvider dataProvider;
private TreeGrid treeGrid;
private String caption;
}`
`public class TreeNode { private String name; private String description; private UUID code = UUID.randomUUID();
}`