Search code examples
apache-flex

Flex : AdvancedDataGrid columns dataProvider?


I have a AdvancedDataGrid, defined as:

<mx:AdvancedDataGrid id="mainGrid" width="200" height="200" designViewDataType="flat" >
    <mx:columns>
    </mx:columns>
</mx:AdvancedDataGrid>

I am adding dynamically the columns to the grid, and the main question is:

  • How to setup an array or vector as dataprovider to each Column?

P.S. this function I am using to fill up the data:

private function buildUpTheGrid() : void    {

    masterColumns = new Array();
    masterData    = new Array();

    var tempColumn : AdvancedDataGridColumn;


    for( var iY : int = 0; iY < columsCount; iY++ )                 
    {
        masterData.push( new Array() );
        tempColumn           = new AdvancedDataGridColumn();
        tempColumn.width     = 20;

        for( var iX : int = 0; iX < rowsCount; iX++ )
            masterData[ iY ].push( iX );

    //  tempColumn.dataField = ???
        masterColumns.push( tempColumn );
    }

    mainGrid.columns = masterColumns;
    mainGrid.validateNow();
}

Solution

  • Short answer to your question "How to setup an array or vector as dataprovider to each Column ?": You cannot.

    The data 'views' in flex are all row based, not column based. So, for this to work, you'll need to transform your columns into rows. It's a fairly simple algorithm that I'm sure you can figure out.

    As for adding the columns dynamically, you just need to add the columns to an array and then set that array in the 'columns' property of the grid. You'll need to set a 'dataField' property on the column for it to know which data property to display from the row data you've just transformed.