jsTree code example
Example: jstree ajax
$("#schema").jstree({
"core": {
"data": {
"url": url,
"type": "post",
"data": function (node) {
return { "ParentId": node.id };
}
}
},
"search": {
"case_insensitive": true,
"show_only_matches": true,
"show_only_matches_children": true,
ajax: {
"url": url,
"type": "post",
"data": {"yourdata": showtableonly }
}
},
"plugins": ["search"],
});
$("#schema").jstree(true).search("Your Text Here");
Server Side C#
public class TreeState
{
public bool loaded { set; get; }
public bool opened { set; get; }
public bool selected { set; get; }
public bool disbled { set; get; }
}
public class TreeNode
{
public TreeNode()
{
}
public TreeNode(string text)
{
this.text = text;
}
public TreeNode(string text, string icon)
{
this.text = text;
this.icon = icon;
}
public string id { set; get; }
public string parent { set; get; }
public bool children { set; get; }
public string text { get; set; }
public string icon { get; set; }
public TreeState state { set; get; }
public string type { set; get; }
public string style { set; get; }
public object NodeObject { set; get; }
}
[HttpPost]
public JsonResult GetTreeNode(Dictionary<string,string> search)
{
List<TreeNode> tree = new List<TreeNode>();
tree.Add(new TreeNode() {id="1",text="",state=new TreeState() { } });
if(search.ContainsKey("str"))
{
return Json(tree.Select(x=> x.id).ToList());
} else if(search.ContainsKey("Parentid"))
{
return Json(tree);
}
}