Comments (4)
Example of contains any working with jstree 3: https://jsfiddle.net/t067rm8d/5/
"search": {
"case_insensitive": true,
"show_only_matches": true,
"search_callback": function(str, node) {
//search for any of the words entered
var word, words = [];
var searchFor = str.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 ((node.text || "").toLowerCase().indexOf(word) >= 0) {
return true;
}
}
return false;
}
},
plugins: ["search", "wholerow"]`
from jstree.
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;
};
from jstree.
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) :
/*
* jsTree search plugin
* Enables both sync and async search on the tree
* DOES NOT WORK WITH JSON PROGRESSIVE RENDER
*/
(function ($) {
$.expr[':'].jstree_contains_multi = 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;
};
$.expr[':'].jstree_contains = function(a,i,m){
return (a.textContent || a.innerText || "").toLowerCase().indexOf(m[3].toLowerCase())>=0;
};
from jstree.
I will include this with the useful snippets for version 1.0. Thanks :)
from jstree.
Related Issues (20)
- Database demo not working at https://www.jstree.com/demo/ HOT 1
- is there some way to load only part of the whole tree?
- Open/close state not reflected on aria-expanded attribute
- `instance.get_json` does not mention the undetermined states (checkbox plugin) HOT 1
- Hide root
- types-plugin: a_attr/li_attr are not merged to nodes
- move node fails if children are all typed to same?
- possible security issues, feedback needed HOT 1
- Node Position Sequence
- Webpack/encore compatibility - $(...).jstree is not a function HOT 1
- Select all button
- The jstree package is vulnerable to Cross-Site Scripting (XSS)
- Massload plugin only loads one time and does not execute 2nd time HOT 1
- How can I resolve the vulnerability in JSTree's get_node flagged by Checkmarx? HOT 2
- can't make node.state work as expected HOT 1
- get id of of parent node when dropped HOT 2
- How to Display File icon for Files HOT 1
- Non-functional plugins ? HOT 1
- Show a tree structure in dropdown html
- duplicate ids freezes / crashes
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from jstree.