Reputation:
I'm trying to turn my jstree search into ajax search with the following configuration, my problem is, even though it sends "str" to the url and I receive the data in a json ["#id"] like, but jstree still does its normal search
// $.jstree.defaults.search.ajax = true;
$('#node_tree').jstree({
'core' : {
'data': fill_tree(),
},
"plugins": ["search", "state","themes"],
'search': {
'show_only_matches': true,
'ajax': {
'url': '/device/jstree',
'dataType': 'json',
'type': 'GET'
}
My ajax is already working, and I need jstree to show my hard-coded result instead of its default search.
Upvotes: 3
Views: 5912
Reputation: 1
I was facing the same problem in jstree and below configuration worked for me.
Call the search function with below mentioned parameters. # being the root node. (Ref)
$('#tree').jstree(true).search(v, false, true, '#');
The ajax call to the search should return only the parent nodes of the found child. If the search result is child1, child2 then the search ajax should return only the respective parent in json format
["parent1", "parent2"]
Upvotes: 0
Reputation:
Just a reference for anyone with the same problem, even though jstree was sending ajax call correctly, it was showing it's own result instead of mine and I couldn't find any way to change this. So I was resigned to return a whole new JSON data and:
$('#tree').jstree(true).settings.core.data = newJsonData;
$('#tree').jstree(true).refresh();
I know it was not the best option but it did the trick for the moment.
Upvotes: 1
Reputation: 7736
Enable the Ajax Search in JSTree Config.
$.jstree.defaults.search.ajax = true
Refer this for few more information from this answers:
https://stackoverflow.com/a/20316921/1533666
https://stackoverflow.com/a/20278351/1533666
https://stackoverflow.com/a/31646865/1533666
Add data function to your Ajax.
'data' : function(str) {
return { "search_str" : str };
},
Upvotes: 0