Friday, June 19, 2009

Tweaking OLAPCell and OLAPDataGrid to display custom formatted values

Displaying custom formatted data in OLAPDataGrid is a bit tricky because OLAPDataGrid doesn't use the OLAPCell.formattedValue at all due to a bug in its implementation.

However the tweaks I am going to mention are simple and can be used to get this to work. After the tweaks don't forget to build the datavisualization.swc using the steps I have described in one of the earlier posts.

Modifing OLAPCell.as file : Modify the constructor to set a formatted value into the _formattedValue property

public function OLAPCell(value:Number, formattedValue:String=null)

{

_value = value;

_formattedValue = insert any custom formatting logic using value ;

}

Modify OLAPDataGrid.as : Somewhere around line 769 we can find the following line

label = cell && !isNaN(cell.value) ? String(cell.value) : defaultCellString;

Modify this to read as follows

label = cell && !isNaN(cell.value) ? String(cell.formattedValue) : defaultCellString;

Build the swc and use it in your app to get custom formatting. Of-course some more tweaking it required to make this generic and supply a Flex formatter directly to OLAPDataGrid. I am sure it can be easily figured out !

8 comments:

MENDONÇA said...

miHow can I have the sources of datavisualization.swc to change the class and OLAPDatagrid.as OLAPCell.as and compile again? Contents I could the way to do the test .... thanks

Sreenivas said...

I have explained where to find the source here

And how to build it after making changes here

MENDONÇA said...
This comment has been removed by the author.
MENDONÇA said...

Sreenivas
would make the formatting of the values of type pivotcomponent with olapdatagrig, simple ..?

NumberFormatter id="fmtNumber" precision="2"

Nancy said...

I know this is way off subject, but here goes..

I'm having some really weird issues with populating an advanceddatagrid with xmlList (quoteXMLList) data. Here is my situation. I've got an xmllist that, when looking at one entry (xmlList[0]), has xml looking like this.

[response]
[cost]
[totalCost]20[/totalCost]
[/cost]
[/response]

Now I'm trying to get totalCost as a datafield and for it to show up in a adg column. So I tried something like this

[mx:AdvancedDataGrid editable="false" width="100%" height="100%" variableRowHeight="true" id="quoteDataGrid" dataProvider="{this.quoteXMLList}"]
[mx:columns[
[mx:AdvancedDataGridColumn dataField="cost.totalCost" headerText="Total Cost" /]

But nothing shows up. So, I changed my dataprovider to this.quoteXMLList.cost and put dataField="totalCost" and it shows up fine. But I can't do that cause I have more info I need to gather for other columns that is in different areas of the xml in the current xmlList. So, can you not put e4x notation in datafield, if not what do I do here? Thanks in advance.

Sreenivas said...

You can try using what is described here http://flexpearls.blogspot.com/2008/01/extending-dgcolumn-and-adgcolumn-to.html or use a custom itemRenderer for that column and access and display the 'totalCost' field using the data member.

Research Writer said...

Many institutions limit access to their online information. Making this information available will be an asset to all.
Custom Paper Writing

Popandopulos Effendi said...

For people who are part of tertiary education it comes as no secret that any overview requires passing judgment upon given information. If you look for someone who would write dissertation proposal as good as papersmart quickly for your college professor come to our online service. We employ only educated people with good skills and bright brains aware of many serious scientific features of any kind of problem of a modern life.