Comments (5)
Yeah, I should at least put some docs up on how to perform these types of filtering. This has come up three times now.
from react-arborist.
Just realized this is a duplicate of #111 - though that one is already closed, so maybe it's worth to keep this discussion open. I did not try creating a matcher using the searchMatch
option. If I'm able to, might be something to document here.
from react-arborist.
I've found a solution that works, potentially janky though:
searchMatch={(node, searchTerm) => {
// If the node itself matches the search term
if (searchMatch(node, searchTerm)) {
trueMatches.add(node.id)
return true
}
// If the node is the child of a matching element
if (trueMatches.has(node.parent?.id)) {
return true
}
// TODO: Grandchildren?
return false
}}
I have some complicated logic for determining a match, so I extracted it into a function called searchMatch
. If the node itself matches, I add its ID to a set, and return true. If the node itself doesn't match, but it's parent's ID is in the set, then it's the child of a match, and I return true.
This implementation only includes the first generation (which is fine for my application), but recursion should be able to find a child at any depth 👍
The inclusion of the set slightly complicates things too, like you'll have to clear your set every time you clear your search term, etc.
from react-arborist.
Hi, I had figured out a solution to do this, had posted at #177. You may consider the solution and modify yourself.
from react-arborist.
@lsfgrd Hi dear friend.
Can you help me? According to the tree structure that you have asked and placed in your question, you have used a check box. Please guide me with example how can I manage selected by putting check box?
I have opened a topic about the checkbox in the link below, please guide me there.
from react-arborist.
Related Issues (20)
- Item count increases randomly HOT 1
- Property 'select' does not exist on type 'never' HOT 1
- Hidden flag for nodes HOT 1
- Doesn't work on remix HOT 1
- React Aborist ScrollTo bug with deep nested nodes HOT 1
- [HELP] Multiple selection from array of ids
- Render 1 million root elements on different screen sizes
- Deselect not firing event HOT 2
- How to drag a node INTO a leaf node
- Better scrolling while user is dragging
- [Question] How to build a tree with some folders open and some closed? HOT 1
- There is a bug in using the tree.update method to set height.
- Duplicate HTML5 backend error HOT 5
- Deletion behavior can be unintuitive HOT 4
- Lack of control over delete leads to some weird scenarios HOT 2
- Should we be able to focus the entire tree? HOT 2
- Using react-arborist in an app seems to break file & folder drop on <input type="file" multiple /> elements HOT 2
- How rename `name` to `node_name` and create node with name
- Drag and Drop should be handled within the level hierarchy
- How do you implement controlled select?
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 react-arborist.