问题
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)
回答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 !!
来源:https://stackoverflow.com/questions/24700093/how-to-know-if-there-are-sub-items-nodes-in-an-advanceddatagrid