Creating a table

0 views
Skip to first unread message

Akhil Agrawal

unread,
Mar 4, 2009, 4:24:48 AM3/4/09
to Flex India Community
Hi,
i want to crate a table for displaying data in flex. how can i do
this. if i use datagrid control or any control how to add column to
that at run time because no. of columns may vary....

thanx

regards
akhil agrawal

sudhi

unread,
Mar 4, 2009, 4:38:07 AM3/4/09
to Flex India Community
Dear Akhil,

Use a datagrid for this.
Use an array or array collection as the dataprovider for the Datagrid,

Change the dataprovider at runtime.

This should solve your problem

Regards
Sudhi.

Flexian_NGL ,@Bangalore

unread,
Mar 4, 2009, 4:38:21 AM3/4/09
to flex_...@googlegroups.com
There is no table in flex, you could vbox and hbox in combination for obtaining a table

--
Thanks & Regards
GK

kalpesh mahida

unread,
Mar 4, 2009, 4:43:20 AM3/4/09
to flex_...@googlegroups.com
You can crate DataGridColumn dynamically by creating an object of DataGridColumn class like myColumn = new DataGridColumn(); and then make a array from these columns like arrCol.push(myColumn); and then columns property of your datagrid as myDg.columns = arrCol;

I hope this helps you please reply

Regards,
Kalpesh Mahida

Akhil Agrawal

unread,
Mar 4, 2009, 9:41:29 AM3/4/09
to Flex India Community
it is not working header text is not displayed

On Mar 4, 2:43 pm, kalpesh mahida <kalpesh.mah...@gmail.com> wrote:
> You can crate DataGridColumn dynamically by creating an object of
> DataGridColumn class like myColumn = new DataGridColumn(); and then make a
> array from these columns like arrCol.push(myColumn); and then columns
> property of your datagrid as myDg.columns = arrCol;
>
> I hope this helps you please reply
>
> Regards,
> Kalpesh Mahida
>

Akhil Agrawal

unread,
Mar 4, 2009, 9:43:53 AM3/4/09
to Flex India Community
@kalpesh
it is not working header text is not displayed

Akhil Agrawal

unread,
Mar 5, 2009, 12:07:18 AM3/5/09
to Flex India Community
@kalpesh
its working buddy thanx

kalpesh mahida

unread,
Mar 5, 2009, 12:13:44 AM3/5/09
to flex_...@googlegroups.com
Hi Akhil,

Here is the two way of creating a data grid dynamically out those two way one is commented for now so you can remove comment line and try that one also, hope these will help you, please reply

<?xml version="1.0" encoding="utf-8"?>
<mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="initApp()">
  <mx:Script>
    <![CDATA[
      import mx.controls.dataGridClasses.DataGridColumn;
      import mx.controls.DataGrid;
      import mx.collections.ArrayCollection;
     
      private var myColumn:DataGridColumn;
      private var arrCol:Array = new Array();
      private var myDg:DataGrid;
     
      [Bindable]
      private var dataArr:ArrayCollection =
        new ArrayCollection
        (
          [
            {label0:0, label1:"label1", label2:"label2", label3:"label3", label4:"label4"},
            {label0:1, label1:"label1", label2:"label2", label3:"label3", label4:"label4"},
            {label0:2, label1:"label1", label2:"label2", label3:"label3", label4:"label4"}
          ]
        );
     
      private var labelArr:Array = new Array("label0","label1","label1","label2","label4");
                  
      private function initApp():void{
        var arrCollection:ArrayCollection = new ArrayCollection();
       
        if( myDg != null ) {
                     myCanvas.removeChild( myDg );
                     myDg = null;
                }
                myDg = new DataGrid();
               
                /* for(var loopRow:int = 0; loopRow < 5; loopRow++)
                {
                    var arrCell:Array = new Array;   
                    for( var loopCol:int = 0; loopCol < 5;loopCol++ )
                    {
                        var str:String = 'cell['+loopRow+']['+loopCol+']';
                        arrCell.push(str);
                    }
                    arrCollection.addItem(arrCell);
                }
                myDg.dataProvider = arrCollection;
                myCanvas.addChild( myDg );
                */
               
        for( var i:int = 0; i < 5; i++ ){
          myColumn = new DataGridColumn();
          myColumn.headerText = 'Column'+i;
          myColumn.dataField = labelArr[i];
          arrCol.push( myColumn );
        }
        myDg.columns = arrCol;
        myDg.dataProvider = dataArr;
        myCanvas.addChild( myDg );
      }
    ]]>
  </mx:Script>
  <mx:Canvas id="myCanvas" />
</mx:Application>


Regards,
Kalpesh Mahida
Reply all
Reply to author
Forward
0 new messages