Then it seems like whether the fetch is coming from invalidateCache() or is the initial fetch, in both cases, you'd want to do the same thing.
Announcement
Collapse
No announcement yet.
X
-
TreeGrid.invalidateCache() will attempt to re-load the entire tree that is in the grid based on node expansions. I am noticing that the grid will re-send all parentNodeIDs requests to do so. Including nodes that do not return any data (edge of the tree leaf nodes).
I am trying to avoid multiple requests going to the server by returning the entire tree on the root node. But even doing this, I see the leaf node requests being sent to the server even though there is nothing to return in which I simple return an empty set like this on the server
Code:DSResponse dsResponse = new DSResponse(); ArrayList arrayList = new ArrayList(); dsResponse.setData(arrayList.toArray()); dsResponse.setStartRow(0); dsResponse.setEndRow(arrayList.size()); dsResponse.setTotalRows(arrayList.size()); return dsResponse;
Code:Record[] cacheRecords = treeGrid.getDataSource().getCacheData();
Last edited by JLivermore; 18 Sep 2014, 09:35.
Comment
-
I have figured out a solution to my issue - when doing a TreeGrid.invalidateCache() I would like to minimize the number of DSRequests being sent to the server so on the root node FETCH, I return the entire tree that *has been* loaded up too that point. But I was seeing additional DSRequests being sent for empty folder nodes (nodes that were expanded but did not have any children below). Those additional DSRequests were being sent even though the entire tree data was returned on the root node FETCH. It appears the TreeGrid keeps track of all load-on-demand requests and simply resends them.
So to avoid the empty folder DSrequests being sent again upon a TreeGrid.invalidateCache() I setup a FolderOpenedHandler and a DataArrivedHandler for the TreeGrid that essentially removes the empty-load-on-demand request for empty folder nodes.
Code:treeGrid.addFolderOpenedHandler(new FolderOpenedHandler() { @Override public void onFolderOpened(FolderOpenedEvent event) { TreeNode treeNode = event.getNode(); /* * By unloading the children from the EDGE_OF_TREE nodes, TreeGrid.invalidateCache() will not send * FETCHes for the EDGE_OF_TREE nodes that are empty and have been expanded. This block sets up * the emptyTreeNode variable to check in the DataArrivedHandler. */ if(!treeGrid.getData().hasChildren(treeNode)) emptyTreeNode = treeNode; else emptyTreeNode = null; } });
Code:treeGrid.addDataArrivedHandler(new DataArrivedHandler() { @Override public void onDataArrived(DataArrivedEvent event) { if(treeGrid.getRecords() != null && treeGrid.getRecords().length > 0) treeGrid.getData().openFolder(Tree.nodeForRecord(treeGrid.getRecords()[0])); modelMediator.setStatusBarLoadingEnd("Ready"); /* * By unloading the children from the EDGE_OF_TREE nodes, TreeGrid.invalidateCache() will not send * FETCHes for the EDGE_OF_TREE nodes that are empty and have been expanded. */ if(emptyTreeNode != null) { if(!treeGrid.getData().hasChildren(emptyTreeNode)) { treeGrid.getData().unloadChildren(emptyTreeNode); } emptyTreeNode = null; } } });
Comment
-
What the ResultTree remembers is which nodes were open, and it opens the same nodes. You can disable this behavior via autoPreserveOpenState.
Again the correct way to return an empty folder and avoid a fetch for its children, as we covered a few post ago:
See Tree DataBinding overview: to return a folder that has no children, return an empty Array for the childrenProperty.
Comment
-
I need the Open State to be preserved, so that is good. I tried several times trying to return an empty folder with children set to zero, but was not able to get it to work as expected.
I asked several times, but you keep pointing me to the Tree Data Binding javadoc. Can you post an example on how to return an empty folder with the children property set to zero?
Comment
-
We're unsure how to make this more explicit - the default childrenProperty is "children" so we are literally talking about a one line call like this:
Code:record.setAttribute("children", new ArrayList());
Comment
-
Hmmm yes, that's what I did as well. OK, I'm clear now, no confusion on my side. Thank you for the explicit example.
this is what I am returning from the server on an empty fetch as seen in the RPC tab from the dev console:
Code:[ { affectedRows:0, data:[ { children:[ ] } ], endRow:1, invalidateCache:false, isDSResponse:true, queueStatus:0, startRow:0, status:0, totalRows:1 } ]
What I see in this case is another node under the node I clicked on, which is an empty node and I'm returning the above DSResponse. Not what I expected?Last edited by JLivermore; 23 Sep 2014, 04:58.
Comment
-
Does the DSResponse I posted above look ok? Because what I see in the TreeGrid after this DSResponse goes back is another empty node under the original node I expanded. Returning this dummy record creates a new subnode?
Just so we are clear, on the server this is the code:
Code:DSResponse dsResponse = new DSResponse(); Map<String, Object> record = new HashMap<String, Object>(); record.put("children", new ArrayList<>()); ArrayList arrayList = new ArrayList(); arrayList.add(record); dsResponse.setData(arrayList); dsResponse.setStartRow(0); dsResponse.setEndRow(arrayList.size()-1); dsResponse.setTotalRows(arrayList.size()); return dsResponse;
Last edited by JLivermore; 23 Sep 2014, 07:45.
Comment
Comment