Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Flex Vertical Datagrid

Can i have a datagrid that displays data vertically instead of horizontally ?

for example, if this is my dataprovider:

array('firstname':'John','lastname':'Doe'),
array('firstname':'Jack','lastname':'Jill')

I want the data to be displayed like this :

Fields        Value1    Value2
Firstname     John      Jack
Lastname      Doe       Jill

and so on .... whats the best way to achieve this .. If i have to extend the datagrid component, please explain how ..

like image 436
Lin Avatar asked Jun 02 '11 11:06

Lin


1 Answers

So this is a hack... but it turns out you can't easily change the flow of the spark datagrid. From what I can tell, you'd need to override just about every component inside it and it'd take a long time. The DataGrid uses its own layout and it seems very set on the subject of 1 row = 1 piece of data.

So... commence hack:

<s:DataGrid rotation="270">
  <s:columns>
    <s:ArrayList>
      <s:GridColumn itemRenderer="unrotate" headerRenderer="headerUnrotate"/>
      <s:GridColumn itemRenderer="unrotate" headerRenderer="headerUnrotate"/>
    </s:ArrayList>
  </s:columns>
</s:DataGrid>

Okay... what did I do? I just rotate the whole datagrid. How do I fix it so we don't have to tilt your head? I un-rotate each column in the itemrenderer. HOLY HACK batman.

here's the item renderer unrotate:

<?xml version="1.0" encoding="utf-8"?>
<s:GridItemRenderer xmlns:fx="http://ns.adobe.com/mxml/2009" 
                xmlns:s="library://ns.adobe.com/flex/spark" 
                xmlns:mx="library://ns.adobe.com/flex/mx" clipAndEnableScrolling="true">

<fx:Script>
    <![CDATA[
        override public function prepare(hasBeenRecycled:Boolean):void {
            lblData.text = data[column.dataField]
        }
    ]]>
</fx:Script>

<s:Label id="lblData" top="9" left="7" rotation="90"/>

</s:GridItemRenderer>

The header code is similar, just rotate 90 to get back to where we started. I know this solution is far from perfect but it's the best I could think of without completely messing with the DataGrid class

You probably also need to override the skin to provide a WIDER header... which is actually a TALLER header since we're rotated 270 degrees. Other then that it should actually work okay...

like image 168
Jonathan Rowny Avatar answered Sep 29 '22 15:09

Jonathan Rowny