0
votes

I created a tree and would like the scroll was for the selected node through a filter . As the example below found on the internet JSFIDDLE: TreeNodeJsFiddle

My Code:

<p:accordionPanel id="apFilter">

<p:remoteCommand name="remoteFilter"
    actionListener="#{mybean.searchNode}"
    update="tree,:form:dataTree, :form:dataTree1, :form:chart" />
<p:outputLabel value="Search: " />
<p:inputText id="filterTree" value="#{myBean.filter}"
    style="width:100px"
    onkeypress="if (event.keyCode == 13) { test(); return false; }" />

<p:outputPanel id="scroll"
    style="width: 100%;height: 100%;overflow: auto;display: block">

    <!-- tree  -->
    <p:tree filter="true" value="#{myBean.root}" var="doc" id="tree"
        style="width:250px; font-size:10px" dynamic="true" cache="false"
        selectionMode="single" selection="#{myBean.selectedNode}">
        <p:ajax event="expand"
            update=":form:dataTree, :form:dataTree1, :form:chart"
            listener="#{myBean.onNodeExpand}" />
        <p:ajax event="select"
            update=":form:dataTree1,:form:dataTree, :form:chart"
            listener="#{myBean.onNodeSelect}" />
        <p:ajax event="unselect"
            update=":form:dataTree,:form:dataTree1,:form:chart"
            listener="#{myBean.onNodeUnselect}" />
        <p:ajax event="collapse"
            update=":form:dataTree1,:form:dataTree, :form:chart"
            listener="#{myBean.onNodeCollapse}" />

        <p:treeNode type="group1" expandedIcon="ui-icon-folder-open"
            collapsedIcon="ui-icon-folder-collapsed">
            <h:outputText value="#{doc.name}" />
        </p:treeNode>

        <p:treeNode type="group2" expandedIcon="ui-icon-folder-open"
            collapsedIcon="ui-icon-folder-collapsed">
            <h:outputText value="#{doc.name}" />
        </p:treeNode>

        <p:treeNode type="group3" icon="ui-icon-document">
            <h:outputText value="#{doc.name}" />
        </p:treeNode>


    </p:tree>
</p:outputPanel>

I tried using the scrollTo as recommended on the link: http://forum.primefaces.org/viewtopic.php?f=3&t=18856 , however did not succeed .

 public void searchNode() {
    selectedNode = myBeanRN.searchFilter(filter);   
    RequestContext context = RequestContext.getCurrentInstance();
    context.scrollTo("apFilter:tree:"+selectedNode.getRowKey());
}

Does anyone know how to go to the selected node equal the example of jsFiddle ?

1
Do you got right client ID? Isn't everything in some h:form or other naming container? Do you got this part apFilter:tree: from inspecting element in html?Geinmachi
I got this part apFilter:tree using firebug and selectedNode.getRowKey() is the key from node who is generated by node path.Débora Cristina
Try a dummy test like to add prependId="false" to h:form and inside the searchNode method scrollTo harcoded node, for example, "apFilter:tree:3". All of this for avoid problems with IDs.Miguel
I used prepend id, but the problem now is that: inside the scroll panel, does not move to the selected node . And out of the Scroll Panel node moves to the selected node , but does not have the component tree scroll bar ( tree is larger).Débora Cristina

1 Answers

1
votes

i used

 <p:scrollPanel>
 <p:tree>
  ...
 </p:tree>
 </p:scrollPanel>

and js on select tree element

var selectedElement = treeWidgetVar.jq.find('span .ui-state-highlight');
if (selectedElement != null && selectedElement != undefined && selectedElement.position() != undefined) {
     var scrollPanel = treeWidgetVar.jq.parent();
     scrollPanel.scrollTop(selectedElement.position().top - scrollPanel.height() / 2);
}