Project

General

Profile

1
<!DOCTYPE html
2
PUBLIC "-//W3C//DTD XHTML 1.0 Strict//EN"
3
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-strict.dtd">
4
<html xmlns="http://www.w3.org/1999/xhtml">
5
<head>
6
	<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
7
	<title>jsTree v.1.0 - Search documentation</title>
8
	<script type="text/javascript" src="../_lib/jquery.js"></script>
9
	<script type="text/javascript" src="../_lib/jquery.cookie.js"></script>
10
	<script type="text/javascript" src="../_lib/jquery.hotkeys.js"></script>
11
	<script type="text/javascript" src="../jquery.jstree.js"></script>
12

    
13
	<link type="text/css" rel="stylesheet" href="syntax/!style.css"/>
14
	<link type="text/css" rel="stylesheet" href="!style.css"/>
15
	<script type="text/javascript" src="syntax/!script.js"></script>
16
</head>
17
<body>
18
<div id="container">
19

    
20
<h1>jsTree v.1.0 - search plugin</h1>
21
<h2>Description</h2>
22
<div id="description">
23
<p>The <code>search</code> plugin enables searching for nodes whose title contains a given string, works on async trees too. All found nodes get the <code>jstree-search</code> class applied to their contained <code>a</code> nodes - you can use that class to style search results.</p>
24
</div>
25

    
26
<h2 id="configuration">Configuration</h2>
27
<div class="panel configuration">
28

    
29
<h3>case_insensitive</h3>
30
<p class="meta">A boolean. Default is <code>false</code>.</p>
31
<p>Whether to search in a case-insensitive manner or not.</p>
32

    
33
<h3>ajax</h3>
34
<p class="meta">An object (or <code>false</code> if not used). Default is <code>false</code>.</p>
35
<p>This object can be used to make a request to the server on each search - useful if you are using async trees. That way you can return an array of IDs that need to be loaded before the actual DOM search is performed (so that all the nodes that will match the search are loaded). For example if the user searches for "string", you get that on the server side, check the database and find out that there is a node containing that string. But the node is the child of some other node, etc - so in your response you must return the path to the node (without the node itself) as ids: <code>["#root_node","#child_node_3"]</code>. This means that jstree will load those two nodes before doing the client side search, ensuring that your node will be visible.</p>
36
<p>The ajax config object is pretty much the same as the <a href="http://api.jquery.com/jQuery.ajax/">jQuery ajax settings object</a>.</p>
37
<p>You can set the <code>data</code> option to a function, that will be executed in the current tree's scope (<code>this</code> will be the tree instance) and gets the search string as a paramater. Whatever you return in the function will be sent to the server as data.</p>
38
<p>You can set the <code>url</code> option to a function, that will be executed in the current tree's scope (<code>this</code> will be the tree instance) and gets the search string as a paramater. Whatever you return in the function will be used as the URL of the ajax request.</p>
39
<p>The <code>error</code> and <code>success</code> functions (if present) also fire in the context of the tree, and if you return a value in the <code>success</code> function it will be used as the array of IDs.</p>
40

    
41
</div>
42

    
43
<h2 id="demos">Demos</h2>
44
<div class="panel">
45

    
46
<h3>Searching nodes</h3>
47
<p>Do not open the node - instead - just press the button.</p>
48
<input type="button" class="button" value="Search" id="search" style="" />
49
<div id="demo1" class="demo"></div>
50
<script type="text/javascript" class="source">
51
$(function () {
52
	$("#search").click(function () {
53
		$("#demo1").jstree("search","TARGEt");
54
	});
55
	$("#demo1")
56
		.jstree({ 
57
			"json_data" : {
58
				"data" : [
59
					{ 
60
						"attr" : { "id" : "root_node" },
61
						"data" : "A closed node", 
62
						"state" : "closed"
63
					}
64
				],
65
				"ajax" : {
66
					"url" : "_search_data.json",
67
					"data" : function (n) { 
68
						return { id : n.attr ? n.attr("id") : 0 }; 
69
					}
70
				}
71
			},
72
			"search" : {
73
				"case_insensitive" : true,
74
				"ajax" : {
75
					"url" : "_search_result.json"
76
				}
77
			},
78
			"plugins" : [ "themes", "json_data", "search" ]
79
		})
80
		.bind("search.jstree", function (e, data) {
81
			alert("Found " + data.rslt.nodes.length + " nodes matching '" + data.rslt.str + "'.");
82
		});
83
});
84
</script>
85

    
86
</div>
87

    
88
<h2 id="api">API</h2>
89
<div class="panel api">
90

    
91
<h3 id="search">.search ( str , skip_async )</h3>
92
<p>Searches for nodes matching the supplied string. Triggers an event.</p>
93
<ul class="arguments">
94
	<li>
95
		<code class="tp">string</code> <strong>str</strong>
96
		<p>The string to search for.</p>
97
	</li>
98
	<li>
99
		<code class="tp">boolean</code> <strong>skip_async</strong>
100
		<p>If set to <code>true</code> - skip the async search (if setup in the config). This is used mostly internally.</p>
101
	</li>
102
</ul>
103

    
104
<h3 id="clear_search">.clear_search ( )</h3>
105
<p>Clears the current search. This function is automatically called when doing a new search. Triggers an event.</p>
106

    
107
<h3 id="_search_open">._search_open ( is_callback )</h3>
108
<p>Used internally if async is setup in the config. This functions loads the nodes returned by the server one by one.</p>
109

    
110
</div>
111

    
112
</div>
113
</body>
114
</html>
(20-20/27)