0

I'm using a GroupingCollection with 5 GroupingFields but sometimes my data doesn't have info for one of the GroupingFields. How can I hide that GroupingField when it's null on my data?

This is my GroupingCollection

<mx:GroupingCollection id="gc" source="{reqAnt}">
    <mx:grouping>
        <mx:Grouping>
            <mx:GroupingField name="year" />
            <mx:GroupingField name="month" />
            <mx:GroupingField name="building" />
            <mx:GroupingField name="floor" />
            <mx:GroupingField name="room" />
        </mx:Grouping>
    </mx:grouping>
</mx:GroupingCollection>

and this is an example of my data

2014

January

Building100
  Floor1
    Room1.1
    Room1.2
  Floor2
  Floor3
    Room3.1
    Room3.2

In the case of Floor2, I don't want to show the GroupingField "room" because in my data it is null so I want to hide it. But only in the case of Floor2.

Thank you.

Romasz
  • 29,662
  • 13
  • 79
  • 154

1 Answers1

0

The source of your GroupingCollection is an ArrayCollection ? And where is used your GroupingCollection, in a AdvancedDatagrid ? Whether, you can use a filter on the dataProvider of your ADG!

With a system like this : Make a collection of your dataProvider for apply a filter on it.

private function setFilter(filterFunctionName:Function):void
{
    ICollectionView(yourADG.dataProvider).filterFunction = filterFunctionName;
    ICollectionView(yourADG.dataProvider).refresh();
}

The function below serves like a setter of the filterFunction of your collection! In your case you want a function wich be able to filter "empty nodes" (floor2 in your example)!

public function filter():void 
{
    setFilter(FilterEmptyNode);
}

The function below filter the source, return true if the data is ok, false if it needs to be filtered :

public function FilterEmptyNode():Boolean
{
    // here the loop on your data to test if your node have children or not
}

And you have just to call the function filter when you want the data filtered!

You can see my post with a similar issue : How to know if there are sub items/nodes in an AdvancedDatagrid

I hope this can help a bit (and sorry for my english :s)

Community
  • 1
  • 1
Ant Oine
  • 33
  • 6
  • Ant Oine, I'm sorry I haven't replied yet. My product manager doesn't let me include this on our sprints (I have used a workaround by the time I posted so it's not urgent anymore for the product manager). But I tested a bit your solution and it didn't work. But I think I have to spend more time with it. Hopefully the product manager will let me do it, one day.. – user3682705 Oct 10 '14 at 14:53