0 Replies Latest reply on Apr 14, 2010 1:18 PM by Zolotoj

    dataGrid with dynamic comboboxes

    Zolotoj Level 3

      I have a datagrid with a column that uses a combobox for an item renderer.

      These combo might have different dropdown data for different rows and it is set as the following:

      comboBoxCheckItemRendererDataGridDynamic.mxml

      <?xml version="1.0" encoding="utf-8"?>
      <mx:ComboBox xmlns:fx="http://ns.adobe.com/mxml/2009" 
                      xmlns:s="library://ns.adobe.com/flex/spark" 
                      xmlns:mx="library://ns.adobe.com/flex/mx">
           <fx:Script>
                <![CDATA[
                import mx.events.FlexEvent;
                import mx.collections.ArrayCollection;
                import mx.controls.CheckBox;
                public var datas:XML;
                override public function set data(value:Object):void
                {
                     if(value != null)
                     {
                          super.data = value;
                          dataProvider = datas["sku" + value.sku];
                }               
                public function saveCheckState(evt:Event):void
                {
                     var dataProviderItem:Object = dataProvider.getItemAt(dataProvider.getItemIndex(selectedItem));
                     dataProviderItem.selected = CheckBox(evt.currentTarget).selected;
                     dataProvider.setItemAt(dataProviderItem, dataProvider.getItemIndex(selectedItem));     
                }
                ]]>
           </fx:Script>
           <mx:itemRenderer>
                <fx:Component>
                     <mx:HBox width="100%">
                          <mx:Label text="{XML(data).action}"/>
                          <mx:Spacer width="100%"/>
                          <mx:CheckBox id="check" selected="{XML(data).selected == 'true'}"
                                          change="outerDocument.saveCheckState(event);"/>
                     </mx:HBox>
                </fx:Component>
           </mx:itemRenderer>
      </mx:ComboBox>
      
       
      Main process:
      ...
      var plannedAtions:ClassFactory = new ClassFactory(comboBoxCheckItemRendererDataGridDynamic);
      ...
      plannedAtions.properties = {labelField : "action", datas : resultXML};
      columnObject.itemRenderer = plannedAtions;
       
      ...
      Initially datagrid is empty.
      When I add a row I also execute the following again:
      plannedAtions.properties = {labelField : "action", datas : resultXML};
      columnObject.itemRenderer = plannedAtions;
      where resultXML is
      <VFPData>
        <sku35578>
          <action>Audit Existing Inventory</action>
          <selected>false</selected>
        </sku35578>
      </VFPData>
      
      everyting is fine at this point. DataGrid has one row and the combo has its dropdown portion.
      When I add second row I have the following code running:
      XML(plannedAtions.properties.datas).appendChild(resultXML.(elements("sku35576")));
      plannedAtions.properties = {labelField : "action", datas : resultXML};
      columnObject.itemRenderer = plannedAtions;
      plannedAtions.properties.datas will look like this:
      <VFPData>
        <sku35576>
          <action>Audit Existing Inventory</action>
          <selected>false</selected>
        </sku35576>
      
        <sku35578>
          <action>Audit Existing Inventory</action>
          <selected>false</selected>
        </sku35578>
      
      </VFPData> 
      what's happening is that a second combo will have its dropdown data but the one from the first row loses it.
      
      Any idea? 
      Thanks