Skip to content
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

Filter a tree #1456

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open

Filter a tree #1456

wants to merge 1 commit into from

Conversation

kellerza
Copy link

Would you be interested to add filtering to a tree?

Example of filter behavior here

This PR moves flattenedItem and flattenItems to utils and adds flattenFilter to achieve this

flattenFilter needs a filter function and a list of 'visible' branches.
Output the flattenedItems & expanded keys (maybe this could be useful in the future, but no need to do anything with this)
Once filtered, it would be great to expand a certain branch (adding the key to forceVisible achieves this)

I would appreciate some guidance on the API

@kellerza
Copy link
Author

kellerza commented Dec 5, 2024

I've taken a new approach. Instead of modifying TreeRoot, I madea new component responsible for filtering the input to TreeRoot, it's called TreeData, you pass it items and some filters props and it returns filteredItems in the slot and modifies expanded

  <TreeData
    ref="treedata"
    v-slot="{ filteredItems }"
    v-model:expanded="expanded"
    :items="allItems"
    :filter="textFilter"
    :get-text="(i) => i.title"
  >
    <TreeRoot
      v-model:expanded="expanded"
      :items="filteredItems"
    >
   ...
    </TreeRoot>
  </TreeData>

Might be a cleaner approach?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant