Group and ungroup data in AdvancedDataGrid

Needed to implement a feature that in a AdvancedDataGrid hours ordering the data by the first letter or not. First time I thought it was very difficult as I had done something similar in another project where it should split by examples hours the servers, time servers of the instances.
When looking at this old project, I thought it was very complicated and hard to understand, I returned to livedocs to study a little more.
I used the example of Adobe and basic with some adjustments, I saw what I wanted to do was simpler than I thought.
I have a data layer for simple demonstration, and at first, my food grid with it.
[ACTIONSCRIPT3]
[Bindable]
private var dpFlat:ArrayCollection = new ArrayCollection([
{Region:”Southwest”, Territory:”Arizona”,
Territory_Rep:”Barbara Jennings”, Actual:38865, Estimate:40000},
{Region:”Southwest”, Territory:”Arizona”,
Territory_Rep:”Dana Binn”, Actual:29885, Estimate:30000},
{Region:”Southwest”, Territory:”Central California”,
Territory_Rep:”Joe Smith”, Actual:29134, Estimate:30000},
{Region:”Southwest”, Territory:”Nevada”,
Territory_Rep:”Bethany Pittman”, Actual:52888, Estimate:45000},
{Region:”Southwest”, Territory:”Northern California”,
Territory_Rep:”Lauren Ipsum”, Actual:38805, Estimate:40000},
{Region:”Southwest”, Territory:”Northern California”,
Territory_Rep:”T.R. Smith”, Actual:55498, Estimate:40000},
{Region:”Southwest”, Territory:”Southern California”,
Territory_Rep:”Alice Treu”, Actual:44985, Estimate:45000},
{Region:”Southwest”, Territory:”Southern California”,
Territory_Rep:”Jane Grove”, Actual:44913, Estimate:45000}
]);
[/ACTIONSCRIPT3]
A CheckBox is adding a listener to tell me when he is selected or not.
[MXML]

[/MXML]
My function that handles the event of the CheckBox will do the work group and ungroup data.
[ACTIONSCRIPT]
private function handlerCheck(evt:Event):void
{
if(ckGroup.selected)
{
trace(“selected”);
gc.source = dpFlat;
gc.refresh();
hView = new HierarchicalCollectionView(gc);
myADG.dataProvider = hView;
}
else
{
trace(“no selected”);
myADG.dataProvider = dpFlat;
}
}
[/ACTIONSCRIPT]
I am using the class GroupCollection which is responsible for grouping my data for a particular field to be displayed in AdvancedDataGrid.
[MXML]








[/MXML]
Turning then to HierarchicalCollectionView that provides a hierarchical view of my data.
[ACTIONSCRIPT]
gc.source = dpFlat;
gc.refresh();
hView = new HierarchicalCollectionView(gc);
myADG.dataProvider = hView;
[/ACTIONSCRIPT]
The complete example:
[MXML]



























[/MXML]

references:
http://livedocs.adobe.com/flex/3/html/help.html?content=advdatagrid_06.html

Translations:
Português do Brasil

Was this article helpful? feel free to make a donation and help keep the blog in the air
ActionScript 3.0, Flex ,

Leave a Reply