QTree Filter By Things Other Than A String
-
I have a QTree which implements the normal string filter pattern per the documentation.
I’d like to add some toggles outside of the QTree, to show/hide certain elements based on custom properties in the QTree’s nodes.For example, suppose I have this node structure:
2020
— Alice
— Bob
2021
— Alice
— BobI can use the text filter to successfully search for Alice or Bob. I’d like the toggles to show or hide all of 2021, 2020, etc. Note, this is simplified data.
Having looked at the QTree implementation on GitHub, I can see it is checking if the Filter string is non-empty, before calling the filter function (per https://github.com/quasarframework/quasar/blob/684ed9fbe5320552d69ee32393a305205894fd8c/ui/src/components/tree/QTree.js#L140 )
So, the question is - is there any way people can think of where I can convince the QTree to respond to toggles when the filter string is blank?
In particular, where the filter is blank, I can force the Qtree to filter on my toggles by setting the filter string to something programmatically, and then applying a custom filter function. The problem is when it is cleared again, the function is not applied and all filtering is removed.
Thanks,
Ed -
Generate the tree in the way when you store the key in each node containing the label of each parent that node has (e.g. parent2-key/parent1-key/node-key). Then, in the filter-method=“filterMethod” you will be able to use node.key.indexOf(filterVal) to return bool
Not the best approach, but given the circumstances of using just q-tree, that’s probably the best way I can think of
Let me know if you need an example