2 Replies Latest reply on Mar 2, 2016 10:30 AM by iane54858309

    How do I Populate a nested DataGrid dataProvider inside the cell of a dataGrid

    iane54858309

      <s:DataGrid id="aGrid"

                          textAlign="center"

                          width="100%"

                          dataProvider="{newArray}"

                          gridClick="handleClickEvent(event)">

           <s:columns>

                <s:ArrayList>

                          <s:GridColumn dataField="mN" headerText="MN" editable="false"/>

                          <s:GridColumn dataField="sN" headerText="SN" editable="false"/>

                          <s:GridColumn dataField="sC" headerText="OC" width="65" editable="false"/>

                          <s:GridColumn dataField="sN" headerText="NC" width="65" editable="false"/>

                          <s:GridColumn dataField="sInfo" headerText="Title goes here" width="300" editable="false">

                          <s:itemRenderer>

                                  <fx:Component>

                                      <s:GridItemRenderer>

                                          <s:DataGrid id="sGroup"

                                                      horizontalCenter="0"

                                                      width="100%"

                                                      dataProvider="{parentApplication.sGI}"

                                                      initialize="sGroup.columnHeaderGroup.height=0">

                                              <s:columns>

                                                  <s:ArrayList>

                                                      <s:GridColumn dataField="ssN" headerText="" width="150"/>

                                                      <s:GridColumn dataField="ssC"  headerText="" width="74"/>

                                                      <s:GridColumn dataField="ssNC" headerText="" width="74"/>

                                                  </s:ArrayList>

                                              </s:columns>                                   

                                          </s:DataGrid>

                                          <fx:Script>

                                              <![CDATA[

                                                  import mx.rpc.http.HTTPService;

                                                  import mx.rpc.events.FaultEvent;

                                                  import mx.rpc.events.ResultEvent;

                                                  import flash.events.*;

                                                  import spark.events.*;

                                                  import mx.controls.*;

                                                  import mx.collections.*;

                                                  import mx.utils.ArrayUtil;

                                                  import mx.core.FlexGlobals;

                                                  import mx.managers.PopUpManager;

                                                  import mx.events.*;

                                                  import mx.utils.ObjectUtil;

                                                 

                                                  public function handleClickEvent(event:GridEvent):void

                                                  {

                                                      var tempObj:Object = event.grid.dataGrid.dataProvider;

                                                      Alert.show(ObjectUtil.toString(tempObj));

                                                      event.grid.dataGrid.dataProvider = parentApplication.sGI;

                                                      Alert.show(ObjectUtil.toString(parentApplication.sGI));

                                                      Alert.show(ObjectUtil.toString(sdlGroup.dataProvider));

                                                      var tempObj2:Object = new Object();

                                                      tempObj2["ssC"]    = 1;

                                                      tempObj2["ssN"]   = "name";

                                                      tempObj2["ssNC"] = 2;            

                                                      parentApplication.sGI.addItem(tempObj2);                

                                                  }                                                                                       

                                              ]]>

                                          </fx:Script>

                                      </s:GridItemRenderer>

                                  </fx:Component>

                              </s:itemRenderer>

                          </s:GridColumn>

                          <s:GridColumn dataField="tx" headerText="TX" editable="false"/>

                          <s:GridColumn dataField="txc" headerText="TXC" width="65" editable="false"/>

                          <s:GridColumn dataField="txnc" headerText="TXNC" width="65" editable="true" itemRendererFunction="testFunction"/>                                       

                      </s:ArrayList>

                  </s:columns>

              </s:DataGrid>

        • 1. Re: How do I Populate a nested DataGrid dataProvider inside the cell of a dataGrid
          iane54858309 Level 1

          Accidentally submitted the above question without a question!  Given the above mxml, containing a nested dataGrid, any ideas on how to populate the nested dataGrid's dataprovider? I have tried a few things inside the gridClick function just as a test. But the Alert shows the nested dataGrid dataProvider as null everytime. sGI is a public bindable array collection.

          • 2. Re: How do I Populate a nested DataGrid dataProvider inside the cell of a dataGrid
            iane54858309 Level 1

            I case anyone is interested; I forgot that the datagrid has the data variable available for use. Therefore in my actionscript I loop through data continously populating new instances fo an object, and store those objects in an arrayCollection.

             

            [Bindable]

            public var aTestArray:ArrayCollection = new ArrayCollection();

            obj:Object = new Object();

            obj["1"] = entry;

            obj["2"] = entry;

            obj["internalArray"] = returnAnArray();

            aTestArray.addItem(obj);

             

             

            where returnAnArray behaves much like the above code but the function returns an ArrayCollection.

            [Bindable]

            public var aTempArray:ArrayCollection = new ArrayCollection();

            obj:Object = new Object();

            obj["1"] = entry;

            obj["2"] = entry;

            aTempArray.addItem(obj);

            return aTempArray;

             

            For each row in the parent datagrid I can use data.internalArray as the dataProvider for the nested dataGrid.

            dataProvider="{parentApplication.sGI}" now appears as dataProvider="{data.internalArray}"