1

ZK iterate to search in huge tree

asked 2015-07-09 10:23:54 +0800

roma2907 gravatar image roma2907
11 1

I have a huge tree and a textbox to search in the tree, when i type a word in the search field, i have a javascript script which iterate on each nodes of the tree to find nodes which are equals at the search field. My problem is that the script don't iterate on all the tree, it's just iterate on the fifty first nodes because ZK don't generate all the nodes in the DOM.

Zk generate after first fifty nodes this HTML for each node,

<span class="z-tree-line z-tree-spacer">&nbsp;</span><span class="z-tree-line z-tree-spacer">&nbsp;</span>

so javascript can't process these nodes.

I use DefaultTreeModel as tree model.

<tree id="treeview"  class="arbre-contrat"  model="@bind(vm.contratTreeModel)" selectedItem="@bind(vm.selectedContratTreeNode)"> 
                    <template name="model" var="node">
                        <treeitem open="@bind(node.open)" id="${node.data.hierarchyId}">
                            <treerow sclass="${node.data.dataType.cssClass}" >  
                                <treecell onClick="@command('openNode',node=node)" >            
                                        <label value="${node.data.label}"/>
                                </treecell>
                            </treerow>
                        </treeitem>
                    </template>
                </tree>

Anyone have a solution to iterate all the tree ?

delete flag offensive retag edit

5 Answers

Sort by ยป oldest newest most voted
0

answered 2015-07-09 10:53:41 +0800

chillworld gravatar image chillworld flag of Belgium
5322 4 9
https://github.com/chillw...

updated 2015-07-10 07:22:43 +0800

Hey Roma,

The only solution like you suggest it, is opening the whole tree and close it afterwards.
But I like to point out, this will not be good.
Your performance will decrease a lot, because it's a huge tree.

I think your problem is how you do the search.
Most treemodels implement the TreeOpenableModel, so why don't you search in the viewmodel and eventually open just those nodes?

ZK will render them at that point, without rendering all your items.
If your script highlights the text, you can always run after the command the script.

Hope you can figure it out now.

Edit:

While I did try to make you clear to try separate the javascript and the rendering.
So try this :

@Command("openSearchTextNode")
public void openSearchTextNode(@ContextParam(ContextType.BINDER) Binder binder) {
    if (StringUtils.isNotEmpty(searchText)) {

        //root node
        TreeNode<OctaveTreeRow> contratNode = contratTreeModel.getRoot().getChildAt(0);
        //open node if the node contains the value
        searchTextInChild(contratNode, searchText);

        //like BindUtils.postNotifyChange(null, null, this, "contratTreeModel");
        notifyChange("contratTreeModel");
        binder.postCommand("callJavaScript", null);
    }

}

@Command
public void callJavaScript() {
    // js call
    Clients.evalJavaScript("updateSearchDisplay(true);");
}

Greetz chill.

link publish delete flag offensive edit
0

answered 2015-07-09 12:22:21 +0800

roma2907 gravatar image roma2907
11 1

The issue with doing the search on the Viewmodel side is that actualy my search Js script changes the node dom to add tag around the searched text.

Don't really see how would i do it if the search is done back side, i cannot pass html in my node ?

link publish delete flag offensive edit

Comments

The opening of the nodes is for rendering them. You can always trigger your script later(and close the nodes). To do this you have to echo an event so that the Gui can render first your opened items before we call the javascript. Afterwards we can do Clients.evalJavaScript("mineFunction()");

chillworld ( 2015-07-09 12:39:17 +0800 )edit
0

answered 2015-07-09 13:49:30 +0800

roma2907 gravatar image roma2907
11 1

I will explain more my situation, i have already an algorithm which open nodes if the node contains the value of the searched text. After that i call my javascript function to hightlight with

Clients.evalJavaScript("window.setTimeout('updateSearchDisplay(true)',100);");

But after, all my nodes that are equals to my searched text are not highlighted, because in the dom some nodes have this value:

<span class="z-tree-line z-tree-spacer"> </span><span class="z-tree-line z-tree-spacer"> </span>
link publish delete flag offensive edit

Comments

let me guess, opening the nodes and clients.eval is in same command?

chillworld ( 2015-07-09 13:53:17 +0800 )edit

if not, can you create a small fiddle where you reproduce this problem?

chillworld ( 2015-07-09 14:02:44 +0800 )edit
0

answered 2015-07-09 14:51:15 +0800

roma2907 gravatar image roma2907
11 1

yes,I open my nodes and call js in the same command

@Command("openSearchTextNode")
public void openSearchTextNode() {
    if (StringUtils.isNotEmpty(searchText)) {

        //root node
        TreeNode<OctaveTreeRow> contratNode = contratTreeModel.getRoot().getChildAt(0);
        //open node if the node contains the value
        searchTextInChild(contratNode, searchText);

        //like BindUtils.postNotifyChange(null, null, this, "contratTreeModel");
        notifyChange("contratTreeModel");
        // js call
        Clients.evalJavaScript("updateSearchDisplay(true);");
    }
}
link publish delete flag offensive edit
0

answered 2015-07-09 15:02:19 +0800

roma2907 gravatar image roma2907
11 1

when I scroll down, i notice that the tree reload arrived at a place

link publish delete flag offensive edit
Your answer
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
1 follower

RSS

Stats

Asked: 2015-07-09 10:23:54 +0800

Seen: 38 times

Last updated: Jul 10 '15

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