Tree grid correlation

protected Stream<FileGrids> fetchChildrenFromBackEnd(HierarchicalQuery<FileGrids, Void> query) {
	return list.stream();
}

now I need Grids can lazily load data ,but when the method returns, subsequent data cannot be loaded ,and I don’t know how this method gets called either, right

Is there a way to load a large amount of data in batches, say 100 at a time, and when I modify or delete one row of data, I don’t need to refresh the entire grid and cause the hierarchy to shrink

Hi,

I’m not sure about your need.

By default the TreeGrid is loading the data this way:

  • rootItems (by default a page of 50 items)
  • if one node is expanded and visible on the client side, it reads the 50 first children.

To refresh an item and its children, you can use dataProvider().refreshItem(node, true), that should help you to refresh only some part of the TreeGrid.

AbstractBackEndHierarchicalDataProvider<FileGrids, Void>() {
			
			private static final long serialVersionUID = 1L;

			String filePath = backupPath;
			
			@Override
			public int getChildCount(HierarchicalQuery<FileGrids, Void> query) {
				return 200;
			}

			@Override
			public boolean hasChildren(FileGrids item) {
				return true;
			}
			
			@Override
			protected Stream<FileGrids> fetchChildrenFromBackEnd(HierarchicalQuery<FileGrids, Void> query) {
				
				int offset = query.getOffset();
				int limit = query.getLimit();
				String parent="";
				
				List<FileGrids> list = new ArrayList<FileGrids>();
			
				if(query.getParent()!=null){
					parent = query.getParent().getfilePath()+".";
					LOG.warn("query.getParent() = "+query.getParent().getName());
				}
				LOG.warn("parent = "+parent+";offset = "+offset+"; limit = "+limit+";");
				for(int i=offset;i<offset+limit;i++){
					Date date = new Date();
					SimpleDateFormat sdf = new SimpleDateFormat("HH:mm:ss.ssss");
					String str = sdf.format(date);
					list.add(new FileGrids(str, parent+i, "0", parent+i, true));

				}
				return list.stream();

			}
		}

In Screenshot 1, the data lazily loaded by the node is not displayed correctly.
In Screenshot 2, the log shows that the parent node was lost after the first 15 items were loaded.
I would like to know how to avoid this problem, thank you

18460439.png
18460442.png

I’m not sure how it can work because the list is always generated based on random data.

Basically if the component is fetching a node twice it will have 2 different result ?