treant-js icon indicating copy to clipboard operation
treant-js copied to clipboard

Filtering nodes

Open semagarcia opened this issue 7 years ago • 0 comments

Hi,

I am working with a huge tree in JSON format. The structure is a bit complex, because I have some levels "empty" (I mean, without nodes; similar to pseudo option, but implemented in another way). All other features (animations, collapse, scrollbar...) work without problem.

My question is about the "filtering" feature. What I'd want is to have the possibility to define a flag attribute for each node, for instance, in that way:

{ text: { name: 'xxxx', desc: 'yyyy' }, image: './assets/generic-female-avatar.png', HTMLclass: 'card-node', filter: true/false }

As another issue says, to update the state of the tree we should pass again (destroy and create it again) the new tree. My idea is to have always an object updated (including the filter criteria attributes), and if I'd want to filter I just need to pass this object. If I'd want reset the filter option, I just override all the attributes to false. The process for filtering, to summarise it, will consist of:

  1. Update the tree selecting which nodes/branches should appear or not according to the filter attribute.
  2. Destroy and create.
  3. [If we want to remove the filter] Override the original structure with all filter fields set to false.

This feature is different to collapse one, because we could need both: firstly I need to apply a filter, and then, play with collapse switcher to show or hide more or less nodes.

If you have doubts, please, don't hesitate to contact me. Or even, if you could tell me how apply this feature, I could make a PR to implement it.

Thanks.

semagarcia avatar Jul 12 '17 14:07 semagarcia