Search, open and focus to the searching element

436 views
Skip to first unread message

Fabrice LEGRAND

unread,
Mar 23, 2015, 8:54:34 AM3/23/15
to jst...@googlegroups.com
Hello,
I have this configuration for my tree :

$(document).ready(function(){
$("#arbre").jstree({
        "plugins" : [ "json_data", "themes", "ui", "search","massload", "core"],      
        "search" : {
            "case_sensitive": false,
            "ajax" : {
                "url" : "service/rech",
                "data" : {}
                }
        },
"massload" : function (nodes, callback){
$.get("/service/max?node="+ nodes.join(","))
.node(function(data){
callback(data);
})
};
        "core" : {
            "check_callback": true,
            "multiple": false,
            "worker": false,
            "expand_selected_onload": true,
            "opened": true,
            "themes": {
                "dots" : false,
                "responsive": true,
                "icons": true},
            "data": {
                "url": function (node) {
                    console.log(node.id);
                    return node.id === '#' ?
                            "/service/top":
                "/service/mere"
                },
                "data" : function (node) {

                    return {'id' : node.id};
                }

            } }
    });
});
});

And I search with this function :
$(document).ready(function(){
$(".situation").on("click", function(e){
var id = $(this).attr('id');
e.preventDefault();
$("#arbre").jstree(true).search(id);
$(this).tab('show);
});
});

The result return a JSON with id of node to open to arrived on the node searching. But the trees isn't deploying to the node ..
If the node is alreardy open, i didn't have focus and isn't highlight.

How to do pls ?

Thanks, best regards

Ivan Bozhanov

unread,
Mar 23, 2015, 10:57:36 AM3/23/15
to jst...@googlegroups.com
Sorry, I did not understand the question.
The search plugin AJAX functionality will hit your service, it must respond with an array of parent IDs to open, jstree will load those IDs, then it will repeat the search on the client side, any node that matches will be revealed (its parents will be opened).
Matches will NOT be selected or highlighted - you can do that yourself if you listen for the search.jstree event.

Best regards,
Ivan

Fabrice LEGRAND

unread,
Mar 23, 2015, 11:38:36 AM3/23/15
to jst...@googlegroups.com
For example :
I search id : 10 with parent 15.
The array returned was : { 25,20,15}
25 is the top.

But the tree didn't load those IDs.

Ivan Bozhanov

unread,
Mar 23, 2015, 1:41:54 PM3/23/15
to jst...@googlegroups.com
This is not an array, this is invalid JSON: { 25,20,15}

Fabrice LEGRAND

unread,
Mar 23, 2015, 4:54:14 PM3/23/15
to jst...@googlegroups.com
Sorry, i wasn't accurate in my answer ....
The array return is ["25", "20", "15" ] and is transform in to a json {"25", "20", "15"}. This is invalid ?

Ivan Bozhanov

unread,
Mar 23, 2015, 6:19:37 PM3/23/15
to jst...@googlegroups.com
Just make sure what you return is a valid ARRAY of IDs, use jsonlint.com to see if your JSON is valid. I can assure you there is no problem with the search plugin.

P.S. Yes, the above is invalid.

Fabrice LEGRAND

unread,
Mar 24, 2015, 3:33:47 AM3/24/15
to jst...@googlegroups.com
It's a valid array. I know your plugin work because, it's work in an another project.

When the result of the search back, i can see i the tree the icon of loading into the parent node but this is will no open.

I haven't bind any action action.
I use bootstrap3, is that there would be a conflict ?

Fabrice LEGRAND

unread,
Mar 24, 2015, 4:24:37 AM3/24/15
to jst...@googlegroups.com
The json was { "0" : "25", "1" : "20", "2" : "15"}

Ivan Bozhanov

unread,
Mar 24, 2015, 7:16:40 AM3/24/15
to jst...@googlegroups.com
This is an OBJECT literal, not an array. Please learn some basic JS, in the mean time use this:

["25", "20", "15"]


Best regards,
Ivan

Fabrice LEGRAND

unread,
Mar 24, 2015, 8:48:18 AM3/24/15
to jst...@googlegroups.com
HI,

fine it's works. I  search by ID but, i didn't write the id in text ....
The searching element must was into the text.


Thanks for reponse.

Best Regards
Reply all
Reply to author
Forward
0 new messages