Thursday, June 14, 2007

AdvancedDataGrid Summary with column grouping

I improved my previous sample with column grouping getting the following look. The new MXML can be found here. One problem I immediately noticed is that one cannot horizontally center the headerText of the columns without centering the column cell text, this is specially a problem with first column. I filed a request for this. The headerText cannot be vertically centered either. However this has been already reported requesting even more options.

14 comments:

CIAhole said...

I've tried to use the formatSummary function in my own ADG and it will not work. The application compiles, but throws a runtime error indicating that getRootModel is not a valid function. I also simply cut and pasted your sample code into a separate application and, again, it compiled, but would not run. Any ideas why this might be happening?

CIAhole said...

Nevermind....I figured it out. The following code works:

if(this.gc.canHaveChildren(data))

in place of:
if(adg.dataProvider.getRootModel().canHaveChildren(data))

this.gc in the above is a reference to the name of your groupingcollection.

Thanks,
M. McConnell

Víctor said...

Do you have the same example with a XML data?.
Thank you and congratulation for this good joob

Sreenivas said...

I have updated the source to use XML. (Also updated it to the released Flex 3 version)

Víctor said...

Dear Sreenivas, can you say me the url from i can get this code please
Thanks

Sreenivas said...

The source link is in the main post. I updated the source in that location itself.

selkking said...

I want to know something..
In your Application...summary row is at fisrt Row each Grouping Column..
But I want that summary row is at last at last Row each Grouping Column..
wait your answer.. response ASAP.

Sreenivas said...

The summaryPlacement property can be used to control the summary row placement.

Vijay Mareddy said...

if(dataGrid.dataProvider is HierarchicalCollectionView){
var hd:HierarchicalData = dataGrid.dataProvider.source as HierarchicalData
if (hd.canHaveChildren(data)){
return { fontWeight:'bold' };
}
}
return {};

sandesh247 said...

(also posted at http://forums.adobe.com/thread/514030)

Hi.

I have some data like so :

{
{ total : 300, year : 2001 }, // total for the entire year
{ total : 300, year : 2001, quarter : 1 }, // total for an entire quarter
{ total : 250, year : 2001, quarter : 1, month : 1 }, // total for a specific month
{ total : 275, year : 2001, quarter : 1, month : 2 },
{ total : 300, year : 2001, quarter : 1, month : 3 },
{ total : 300, year : 2001, quarter : 2 },
{ total : 250, year : 2001, quarter : 2, month : 4 },
{ total : 275, year : 2001, quarter : 2, month : 5 },
{ total : 300, year : 2001, quarter : 2, month : 6 },
{ total : 300, year : 2001, quarter : 3 },
{ total : 250, year : 2001, quarter : 3, month : 7 },
{ total : 275, year : 2001, quarter : 3, month : 8 },
{ total : 300, year : 2001, quarter : 3, month : 9 },
{ total : 300, year : 2001, quarter : 4 },
{ total : 250, year : 2001, quarter : 4, month : 10 },
{ total : 275, year : 2001, quarter : 4, month : 11 },
{ total : 300, year : 2001, quarter : 4, month : 12 },
}

As you can see, the aggregations are embedded in the data. Objects missing the quarter and month field are aggregations for the year, and those missing the month fields are aggregations for quarter.

The aggregations don't follow the inbuilt aggregations of MAX, MIN AVG etc (it is a last-non-empty column, FYI). Is there a way to group this data in an AdvancedDataGrid?

Thanks.

Sreenivas said...

I am unable to understand the problem clearly. I will try to explain from what I have understood.

GroupingCollection can do the grouping without doing any summary calculations. So you can group this data on year and quarter. It would show a tree containing year at the top and quarters as its child. Quarters will have the month rows as the leaf nodes.

If this doesn't solve your problem please point me to a image/sample which shows the exact output required.

sandesh247 said...

Thanks for the reply Sreenivas. I have highlighted my problem in the screenshot at http://i.imgur.com/ffOKX.png . You may also get the mxml from http://etherpad.com/gw2umtQu4V.

Consider the data object

{ total : 300, year : 2001 }

in my example. I want this to be the summary for the year 2001 in the image. However, since the modes month and quarter are missing in the object, it shows up in the "Not Available" section of the grid.

This is the essence of my problem - my collection contains the summaries, and i want to use those. My guess for now is to use a custom function to achieve the functionality i want.

Sreenivas said...

@sandesh For this kind of data you need to implement a custom IHeirarchicalData and return appropriate children. In the getChildren method you need to iterate over the data and detect the appropriate children for rows like {total: x, year: 2001 } which would be the quarter rows and so on.

Nandan said...

How do I add summary Row for Grouped Columns?? Say I have a grouped column ColA, and under this I have sub Columns ColA1, ColA2 and I need summary field for ColA1 and ColA2 that will be placed under the same ColA1 and ColA2. How do I achieve that?