0

To summarize: How can I remove a node branch (level 1) if it has zero Data items? And in turn also remove Node at higher level 0 if it's sub items are (empty or have been) removed?

After much searching on the internet I still need to know if how to find out if an AdvancedDatagrid or a "node" contains children. How to know if it's empty or has "something"? With it, I will be able to filter it with my function.. (Expalined below):

Firstly I apologize for my bad english.

I have an AdvancedDatagrid with for dataProvider an ArrayCollection. I use a GroupingCollection2 to group my data in nodes.

I use a filterFunction on a ICollectionView of dataProvider of the AdvancedDatagrid. It works!

Example of my grouped data :

- Node level 0
  -- Node level 1
     ++ Data 1
     ++ Data 2
     ++ Data 3
  -- Node level 1
     ++ Data 4
     ++ Data 5
- Node level 0
  -- Node level 1
     ++ Data 6
     ++ etc..

I filter only the data which are on "leafs" (Data sub nodes). After my filter function, Data items are correctly filtered!

Example of results after filtering these: Data 2, Data 4, Data 5, Data 6 :

- Node level 0
  -- Node level 1
     ++ Data 1
     ++ Data 3
  -- Node level 1

- Node level 0
  -- Node level 1

For example nodes with "unwanted" Data are correctly filtered out.

BUT I want to filter out those now "empty" nodes too!! Thats is to say How can I remove a node branch (level 1) if it has zero leaf items? And in turn also remove a Node level 0 if it's total sub-branches are zero after they've been removed?

I want this list :

- Node level 0
  -- Node level 1
     ++ Data 1
     ++ Data 3

Thank you in advance.

(ps: i'm available for questions if I was not enough specific)

ketan
  • 19,129
  • 42
  • 60
  • 98
Ant Oine
  • 33
  • 6
  • Cant you just update/recreate the tree using only remaining items as input for new tree setup? I don't use Flex or MXML but isn't there a way to read a "node" length? (i.e will be zero if node is empty"). Anyways with that information you could try some `If/Else` statements. If Node is filtered then remove it from list of "nodes items" and update the tree. Or even If `Node_level_1` has no leafs (leaf.length == 0) then remove Node, If `Node_level_0` has no sub nodes then remove `Node_level_0` – VC.One Jul 11 '14 at 18:59
  • After filtering.. the last 3 items shown is there really a space between `-- Node level 1` and `- Node level 0`? Like it's still holding an invisible slots for **++ Data 4** and **++ Data 5**? Hopefully someone more experienced can help – VC.One Jul 11 '14 at 19:04
  • Exactly ! I'm looking for a way "to read a node length". It exists a way to do that but not with `GroupingCollection` or I don't know this way.. (thank u for corrections by the way) – Ant Oine Jul 15 '14 at 06:53

1 Answers1

1

Well I figured it out finally !!!

My secret is when I group data with GroupingCollection2 I pass to the node grouped some news (with a groupingField). But news are not showed by the itemRenderer of the node. And with a system of substring on these news I use them in my filterFucntion.

Explanations about difference between "basic" grouping and my grouping : In fact when you group data, created nodes contain only the field whereby they've been created.

For instance my data have 4 fiels : domain, test, status, version. I group them by domain & by test like this (it's a example of how my data are showed, with an item renderer different for each level).

BEFORE DATA WERE LIKE THAT:

- domain 1
  -- test 1
     ++ status/version 1
     ++ status/version 2
  -- test 2
     ++ status/version 3
     ++ status/version 4
- domain 2 etc..

But on the leafs (++ rows), after grouping, there is yet data of the fields "grouped". Namely test and domain field!

For summary after basic grouping:

  • data in node level 0 : domain
  • data in node level 1 : test
  • data in leaf level 2 : domain / test / status / version.

After my grouping data showed are the same.

BUT

After my grouping:

  • data in node level 0 : domain
  • data in node level 1 : domain / test
  • data in leaf level 2 : domain / test / status / version.

Thanks to that I can with my filter function (using substring system) know the parent of each node and by the same occasion if the node is empty after a filter!

I think I'm not clear at all and I apologize.. It's really complex so I'm ready to answer to more specific questions if someone meet a similar problem !!

Ant Oine
  • 33
  • 6