jstree ajax

Solutions on MaxInterview for jstree ajax by the best coders in the world

showing results for - "jstree ajax"
Ewenn
09 Jan 2017
1$("#schema").jstree({
2   "core": {
3                "data": {
4                    "url": url,
5                    "type": "post",
6                    "data": function (node) {
7                        return { "ParentId": node.id };
8                    }
9                }
10            },
11   "search": {
12                "case_insensitive": true,
13                "show_only_matches": true,
14                "show_only_matches_children": true,
15                ajax: {
16                    "url": url,
17                    "type": "post",
18                    "data": {"yourdata": showtableonly  }
19                }
20            },
21            "plugins": ["search"], 
22            });
23//Example Search
24$("#schema").jstree(true).search("Your Text Here");
25
26
27Server Side C#
28public class TreeState
29   {    
30 
31       public bool loaded { set; get; }
32       public bool opened { set; get; }
33       public bool selected { set; get; }
34       public bool disbled { set; get; }
35   }
36
37public class TreeNode
38   {
39       public TreeNode()
40       {
41       }
42 
43       public TreeNode(string text)
44       {
45           this.text = text;
46       }
47 
48       public TreeNode(string text, string icon)
49       {
50           this.text = text;
51           this.icon = icon;
52       }
53 
54 
55       public string id { set; get; }
56       public string parent { set; get; }
57       public bool children { set; get; }
58       public string text { get; set; }
59       public string icon { get; set; }
60       public TreeState state { set; get; }
61       public string type { set; get; }
62       public string style { set; get; }
63       public object NodeObject { set; get; }
64   }
65
66
67[HttpPost]
68public JsonResult GetTreeNode(Dictionary<string,string> search)
69{           
70    List<TreeNode> tree = new List<TreeNode>();
71    tree.Add(new TreeNode() {id="1",text="",state=new TreeState() { } });
72    if(search.ContainsKey("str"))
73    {
74        //Do your search by name here
75        //Format return is List<string> of all Id include with parent id
76        //Please make sure the parent id is exist
77
78        //Format ["idA","idAChild1","idAChild2","idAChild2Child1"]
79
80        return Json(tree.Select(x=> x.id).ToList());
81    } else if(search.ContainsKey("Parentid"))
82    {
83        // do your search server side here
84        //Format is List<TreeNode>
85        return Json(tree);
86    }
87  
88}
89