0

Tree scrolls to blank at bottom of list when data refreshed dynamically

asked 2010-02-08 23:41:55 +0800

chrisj gravatar image chrisj
30 1 1 1

I am using a tree to display a list of search results. When the user runs a new search, I completely replace all data in the tree with new results.

The problem I am having occurs when the new tree data has fewer results than the previously displayed tree. The tree object does not resize, but retains its full length, and it scrolls to the blank lines at the bottom of the list.

I can make the tree scroll to the top by using "setSelectedItem", but I don't want to do this. The application uses select events to retrieve more leaves for the tree, and this event will not trigger if the user clicks on an item that has been programmatically selected. (My users will be untrained members of the general public, so I cannot reasonably expect them to cope with this concept.)

My question is - Is there any other way I can force the tree to scroll to a place that actually contains some data? Alternatively, can I force the tree object to resize so that it does not contain blank pages?

Here is the zul definition of my tree:

<tree id="productTree" forward="onSelect=productfinder.onNodeSelect()" rows="10" width="360px">
</tree>

Here is how the tree is declared in java.

  ArrayList allProducts = new ArrayList();
  Tree productTree;
  SimpleTreeModel treeModel;
  SimpleTreeNode rootNode;
      
  rootNode = new PFTreeNode("Products", allProducts);

  //create the tree model
  treeModel = new SimpleTreeModel(rootNode);

Here is how I populate the tree model. The "places" list is retrieved using a call to a web service. (not shown)

        {
          for (int i = 0; i <
                  places.size(); i++)
          {
            NamedPlace place = places.get(i);
            //if place name not in list of feature types to filter
            //add to list
            if (!this.placeNameFilterList.contains(place.getFeatureType()))
            {
              addGmarker(place);
              PFTreeNode placeNode = new PFTreeNode(place, new ArrayList());
              allProducts.add(placeNode);
            }
          }
        }
        productTree.setModel(treeModel);

This works correctly the first time the tree is displayed, but when I repopulate the tree with a new search, it scrolls to the bottom, showing only blank lines below the retrieved data.


Before I refresh with a new query, I clear the model like this:

    //clear the products list
    allProducts.clear();

    //update the tree
    productTree.setModel(treeModel);

The actual data displayed is good. The tree contains all of the data that is expected. My only problem is that ZK forces the tree to scroll to the bottom and display a blank page. Can anyone please suggest how I can avoid this?

Thanks,
Chris

delete flag offensive retag edit

13 Replies

Sort by ยป oldest newest

answered 2010-05-07 16:07:33 +0800

chantspel gravatar image chantspel
12

Was this issue ever addressed by ZK? I believe this is a bug in the code, because the view should automatically adjust to the new tree dynamically.

I'll try to use the suggested work around for the time being.

link publish delete flag offensive edit

answered 2010-05-09 05:36:49 +0800

samchuang gravatar image samchuang
4084 4

Hi

Could someone provide the sample code for this issue ??

link publish delete flag offensive edit

answered 2019-02-26 19:05:19 +0800

subin829 gravatar image subin829
1

Hi

in my tree have several items and that items has childrens

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2010-02-08 23:41:55 +0800

Seen: 816 times

Last updated: Feb 26 '19

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More