-
-
Notifications
You must be signed in to change notification settings - Fork 1.4k
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Search plugin with multi words support (solution in this post) #10
Comments
I've forgotten to trim the input, so the right function (that prevent from selecting everynode in case of extra spaces at the end of search string) :
|
I will include this with the useful snippets for version 1.0. Thanks :) |
vakata
added a commit
that referenced
this issue
Jul 11, 2011
Better create two different contains functions (contains_all and contains_any): $.expr[':'].jstree_contains_all = function(a,i,m) {
var word, words = [];
var searchFor = m[3].toLowerCase().replace(/^\s+/g,'').replace(/\s+$/g,'');
if (searchFor.indexOf(' ') >= 0) {
words = searchFor.split(' ');
}
else {
words = [searchFor];
}
for (var i = 0; i < words.length; i++) {
word = words[i];
if ((a.textContent || a.innerText || "").toLowerCase().indexOf(word) == -1) {
return false;
}
}
return true;
};
$.expr[':'].jstree_contains_any = function(a,i,m) {
var word, words = [];
var searchFor = m[3].toLowerCase().replace(/^\s+/g,'').replace(/\s+$/g,'');
if (searchFor.indexOf(' ') >= 0) {
words = searchFor.split(' ');
}
else {
words = [searchFor];
}
for (var i = 0; i < words.length; i++) {
word = words[i];
if ((a.textContent || a.innerText || "").toLowerCase().indexOf(word) >= 0) {
return true;
}
}
return false;
}; |
Example of contains any working with jstree 3: https://jsfiddle.net/t067rm8d/5/
|
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
I needed to search for multiple words separated by spaces so I give you my function to add to search plugin (currently the search engine plugin only search for one word).
/*
jsTree search plugin
Enables both sync and async search on the tree
DOES NOT WORK WITH JSON PROGRESSIVE RENDER
*/
(function ($) {
That's all
The text was updated successfully, but these errors were encountered: