Git Product home page Git Product logo

Comments (5)

jameskerr avatar jameskerr commented on May 24, 2024 1

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.

lsfgrd avatar lsfgrd commented on May 24, 2024

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.

BrodyRas avatar BrodyRas commented on May 24, 2024

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.

ansoncyx15 avatar ansoncyx15 commented on May 24, 2024

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.

jzarei1996 avatar jzarei1996 commented on May 24, 2024

@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.

#190

from react-arborist.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.