GWT CellTree scroll to arbitrary node

南楼画角 提交于 2020-01-03 06:06:11

问题


i'm coding some kind of objects browser, organized with folders. When user seslects some folder in the list i have to expand an appropriate node in a tree. I've implemented tree expand, element selection in tree, BUT expand might happen at a part of tree that is out of visible area (CellTree is on a ScrollPane). So, i do have an instace of TreeNode - how can i programmatically scroll to make it visible?


回答1:


It's not possible with the current API, but what you can try, and I haven't tested this, but should be easy:

  1. For each object in your tree render and invisible tag, identifying this object, like an <input type="hidden" id="yourObjectId"/>
  2. Make sure you have a SelectionModel when setting up your NodeInfo etc.
  3. When you know what object you want to scroll to, call yourSelectionModel.setSelected(object,true);. That should expand the tree and display your selected object.
  4. At this stage what you want to do is:
Element cellTreeElement = yourCellTree.getElement();
NodeList<Element> objectIds = cellTreeElement.getElementsByTagName("input");
for ( int i=0;i<elementsByTagName.getLength();i++ )
{
   Element e = objectIds .getItem( i );
   if (e.getId().equals( yourObjectId ) {
     e.scrollIntoView();
   }
}

Pretty sure this should work just fine.




回答2:


another version (if you want to move the element to the top of the CellTree):

    Element cellTreeElement = yourCellTree.getElement();
    NodeList<Element> objectIds = cellTreeElement.getElementsByTagName("input");
    for (int j = 0; j < objectIds.getLength(); j++) {
        Element e = objectIds.getItem(j);
        if (e.getId().equals("r" + iDistrictID)) {
            yourCellTree.getElement().getParentElement().getParentElement().setScrollTop(e.getParentElement().getParentElement().getOffsetTop());
        }
    }


来源:https://stackoverflow.com/questions/7980026/gwt-celltree-scroll-to-arbitrary-node

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!