views:

309

answers:

3

I want to have 2 dataproviders for 1 advancedDataGrid: 1 normal and second one for combobox in a one of columns. I want to have this combobox to have data from a column in database (i already have it in arrayCollection). I just don't know how to provide data for comboBox in a way that it doesn't have to read that data from database every time for every comboBox (as custom component). Should I pass arrayCollection to custom component? or do it 'inline' in mxml? what's the best way?

thanks for any help

A: 

Could you not just set the arrayCollection as a property to the object that is being bound to each row?

One row equals one object with a property containing your arrayCollection which is bound to the comboBox.

Chris
A: 

The easiest is to

  • create a static property on your itemrenderer and pass in the data
  • or, lookup the data in the itemrenderer via a global variable
Christophe Herreman
A: 

I assume that field_2 in table1 contains a key to a row in table 2.

Set up your datagrid to use table1 as a provider. Make sure the second column use the custom renderer with a combobox

<mx:AdvancedDataGrid dataProvider="{table1}">
   <mx:groupedColumns>
      <mx:AdvancedDataGridColumn headerText="Column 1" dataField="field_1" />
      <mx:AdvancedDataGridColumn headerText="Column 2" dataField="field_2" 
         itemRenderer="{CustomRenderer}"/>
   </mx:groupedColumns>
</mx:AdvancedDataGrid>

The renderer is just a canvas with a combobox inside it. The combobox use a copy of the table2 data (just create an array collection and fill it one time with the data from the database) as a provider and use the data from table1 to display the selected item.

<mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" dataChange="dataChange()>
   <mx:Script>
      <![CDATA[
         private function dataChange():void
         {
            //Update combobox selected index
            myCombo.selectedIndex(data);
         }
      ]]>
   </mx:Script>

   <mx:ComboBox id="myCombo" dataProvider="{table2_copy}"\>
</mx:Canvas>
Jean-Philippe Goulet