-
FEATURED COMPONENTS
First time here? Check out the FAQ!
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);
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
Hi
Do you mean you will have a big tree, and it will focus to the end? maybe you could consider using paging mode.
or you could use tree.selectItem()
Hi samchuang, and thank you for your suggestions.
samchuang wrote:
>Do you mean you will have a big tree, and it will focus to the end?
It focuses to blank pages, past the end of the tree data.
>maybe you could consider using paging mode.
A possibility, but I would like to fix the problem without this if I can.
>or you could use tree.selectItem()
This will position the tree correctly (I tried and it works), but setting the item to selected causes another problem in my application, so I don't want to do this.
samchuang wrote
>I have another idea, how about using "Clients. moveTo(x, y)"
That sounds interesting. Is there a way to make it scroll the Tree object rather than the whole browser window?
(My browser window is in the right place, only the tree object is focused outside the range of its data)
Hi I'm having similar problem.. I'm rebuilding the tree when new data is added. when i rebuild the the tree horizontal scroll bar gets reset to left position.. i want to maintain the scroll bar in same position after rebuilding the tree. I tried getTop and getLeft both are not returning scroll bar position :( and Clients. moveTo(x, y) moves the browser and not the scroll bar in tree component :( any help is appreciated...
Hi
I found another way of solving the problem, using Clients.scrollIntoView(component), this function will display the compoent you like to display, refer to javadoc
the example using grid, but you could change to use tree,
<zk> <zscript><![CDATA[ String[] data = new String[100]; for(int j=0; j < data.length; ++j) { data = "option "+j; } ListModel strset = new SimpleListModel(data); ]]></zscript> <intbox id="intbox"/> <button label="scroll" > <attribute name="onClick"><![CDATA[ int index = intbox.getValue(); Row row = (Row)grid.getRows().getChildren().get(index); Clients.scrollIntoView(row); ]]></attribute> </button> <grid id="grid" model="${strset}" width="100px" height="100px"> <columns> <column label="options" /> </columns> </grid> </zk>
Asked: 2010-02-08 23:41:55 +0800
Seen: 816 times
Last updated: Feb 26 '19