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 ?
h:form
or other naming container? Do you got this partapFilter:tree:
from inspecting element in html? – GeinmachiprependId="false"
toh:form
and inside thesearchNode
method scrollTo harcoded node, for example,"apFilter:tree:3"
. All of this for avoid problems with IDs. – Miguel