4 Replies Latest reply on May 4, 2011 10:02 AM by ssardar

    AdvancedDataGrid selectedItem is null

    checker2505

      My source is below. When I am click on a cell in AdvancedDataGrid and try to look to the cell value using the selctedItem attribute, the value of the selectedItem is null in the first line of the showPopUp(evt:Event) method.

       

      I am new to AdvancedDataGrid and not sure why that attribute is null. Any help is very much appreciated...

       

      Source Code:

       

      <?xml version="1.0" encoding="utf-8"?>

      <mx:VBox

       

      xmlns:fx="http://ns.adobe.com/mxml/2009"

      xmlns:s="

      library://ns.adobe.com/flex/spark"

      xmlns:mx="

      library://ns.adobe.com/flex/mx"

      minHeight="

      0"

      minWidth="

      0"

      width="

      100%"

      height="

      100%"

      color="

      black">

       

       

      <fx:Script>

      <![CDATA[

       

      protected function Maximize_clickHandler(event:MouseEvent):void

      {

       

      if (maxRestoreButton.label == "Maximize") {

      maxRestoreButton.label =

      "Restore";

       

      this.parent.removeChild(this);

      }

      else {

      maxRestoreButton.label =

      "Maximize";

      }

      }

       

       

      protected function advanceddatagridcolumn1_activateHandler(event:Event):void

      {

       

      // TODO Auto-generated method stub

      }

       

      ]]>

       

      </fx:Script>

       

       

      <fx:Script>

      <![CDATA[

       

      import mx.containers.Canvas;

       

      import mx.core.DragSource;

       

      import mx.core.UIComponent;

       

      import mx.events.*;

       

      import mx.managers.DragManager;

       

       

      // Initializes the drag and drop operation.

       

      private function mouseMoveHandler(event:MouseEvent):void {

       

      // Create a DragSource object.

       

      var ds:DragSource = new DragSource();

       

       

      // Add the data to the object.

      ds.addData(

      this, 'dragInitiator');

       

       

      // Call the DragManager doDrag() method to start the drag.

      DragManager.doDrag(

      this, ds, event);

      }

       

       

      // Called when the user moves the drag indicator onto the drop target.

       

      private function dragEnterHandler(event:DragEvent):void {

       

       

      // Accept the drag only if the user is dragging data

       

      // identified by the 'color' format value.

       

      if (event.dragSource.hasFormat('dragInitiator')) {

       

       

      // Get the drop target component from the event object.

       

      var dropTarget:VBox=VBox(event.currentTarget);

       

      // Accept the drop.

      DragManager.acceptDragDrop(dropTarget);

      }

      }

       

       

      // Called if the target accepts the dragged object and the user

       

      // releases the mouse button while over the Canvas container.

       

      private function dragDropHandler(event:DragEvent):void {

       

       

      // Get the data identified by the color format

       

      // from the drag source.

       

      var dragInitiator:Object = event.dragSource.dataForFormat('dragInitiator');

       

      var x:int = this.parent.getChildIndex(DisplayObject(dragInitiator));

       

       

      var child2:DisplayObject = this.parent.getChildByName("itemsettings");

       

      var x2:int = this.parent.getChildIndex(child2);

       

      parent.addChildAt(child2, x);

      parent.addChildAt(DisplayObject(dragInitiator), x2);

      }

      ]]>

       

      </fx:Script>

       

       

      <fx:Declarations>

       

      <s:ArrayCollection id="arr"/>

       

      </fx:Declarations>

       

      <fx:Script>

      <![CDATA[

       

      import spark.components.supportClasses.ItemRenderer;

       

      import flash.sampler.getInvocationCount;

       

      import mx.containers.Panel;

       

      import mx.controls.dataGridClasses.DataGridItemRenderer;

       

      import mx.skins.ProgrammaticSkin;

       

      import mx.collections.ArrayCollection;

       

      import mx.collections.Grouping;

       

      import mx.collections.GroupingCollection2;

       

      import mx.collections.GroupingField;

       

      import mx.events.DataGridEvent;

       

      import mx.events.ListEvent;

       

      import mx.events.MenuEvent;

       

      import mx.managers.PopUpManager;

       

      import mx.skins.ProgrammaticSkin;

       

      [

      Bindable]

       

      public var dpHierarchy:ArrayCollection = new ArrayCollection([

      {DATALEVEL:

      "Austin DC", children: [

      {DATALEVEL:

      "123451-00", PROD_DESCP:"Prod Desc 1", BDC:"001002003", BDC_SUBGRP:"1", PROD_STAT:"P - Plan", UOM:"CASE", EACHES_PER_UOM:"24",

      MIN_INC_FLG:

      "Auto", TAG:"Tag 1", DLY_ALLOC:"?", FCST_PCT: "?", SKU_MFG_SUBCLS:"06", OVRD_PROD_FLG:"No", ON_OFF_LINE:"Off", PROD_LEAD_TM:"No Components",

      NON_PROD_LEAD_TM:

      "No Components", RECIPE_EXISTS_FLG:"Yes", children: [

      {DATALEVEL:

      "Arlington Plant", EFF_DT:"04-25-2011", END_DT:"12-25-2025", ORD:"SMTWTFS", RECV_WKS:"1234", LOAD_OFFSET:"24", TIME_FENCE:"10", TRANS_LEAD_TM:"1"},

      {DATALEVEL:

      "DBS MFG Plant", EFF_DT:"04-25-2011", END_DT:"12-25-2025", ORD:"SMTWTFS", RECV_WKS:"1234", LOAD_OFFSET:"24", TIME_FENCE:"10", TRANS_LEAD_TM:"1"},

      ]

      },

      {DATALEVEL:

      "123452-00", PROD_DESCP:"Prod Desc 2", BDC:"001002003", BDC_SUBGRP:"1", PROD_STAT:"P - Plan", UOM:"CASE", EACHES_PER_UOM:"24",

      MIN_INC_FLG:

      "Auto", TAG:"Tag 2", DLY_ALLOC:"?", FCST_PCT: "?", SKU_MFG_SUBCLS:"06", OVRD_PROD_FLG:"No", ON_OFF_LINE:"Off", PROD_LEAD_TM:"No Components",

      NON_PROD_LEAD_TM:

      "No Components", RECIPE_EXISTS_FLG:"No", children: [

      {DATALEVEL:

      "Arlington Plant", EFF_DT:"04-25-2011", END_DT:"12-25-2025", ORD:"SMTWTFS", RECV_WKS:"1234", LOAD_OFFSET:"24", TIME_FENCE:"10", TRANS_LEAD_TM:"1"},

      {DATALEVEL:

      "DBS MFG Plant", EFF_DT:"04-25-2011", END_DT:"12-25-2025", ORD:"SMTWTFS", RECV_WKS:"1234", LOAD_OFFSET:"24", TIME_FENCE:"10", TRANS_LEAD_TM:"1"},

      ]

      }

      ]},

       

      {DATALEVEL:

      "Irving Plant", children: [

      {DATALEVEL:

      "123451-00", PROD_DESCP:"Prod Desc 1", BDC:"001002003", BDC_SUBGRP:"1", PROD_STAT:"P - Plan", UOM:"CASE", EACHES_PER_UOM:"24",

      MIN_INC_FLG:

      "Auto", TAG:"Tag 1", DLY_ALLOC:"?", FCST_PCT: "?", SKU_MFG_SUBCLS:"06", OVRD_PROD_FLG:"No", ON_OFF_LINE:"Off", PROD_LEAD_TM:"No Components",

      NON_PROD_LEAD_TM:

      "No Components", RECIPE_EXISTS_FLG:"Yes", children: [

      {DATALEVEL:

      "Arlington Plant", EFF_DT:"04-25-2011", END_DT:"12-25-2025", ORD:"SMTWTFS", RECV_WKS:"1234", LOAD_OFFSET:"24", TIME_FENCE:"10", TRANS_LEAD_TM:"1"},

      {DATALEVEL:

      "DBS MFG Plant", EFF_DT:"04-25-2011", END_DT:"12-25-2025", ORD:"SMTWTFS", RECV_WKS:"1234", LOAD_OFFSET:"24", TIME_FENCE:"10", TRANS_LEAD_TM:"1"},

      ]

      },

      {DATALEVEL:

      "123452-00", PROD_DESCP:"Prod Desc 2", BDC:"001002003", BDC_SUBGRP:"1", PROD_STAT:"P - Plan", UOM:"CASE", EACHES_PER_UOM:"24",

      MIN_INC_FLG:

      "Auto", TAG:"Tag 2", DLY_ALLOC:"?", FCST_PCT: "?", SKU_MFG_SUBCLS:"06", OVRD_PROD_FLG:"No", ON_OFF_LINE:"Off", PROD_LEAD_TM:"No Components",

      NON_PROD_LEAD_TM:

      "No Components", RECIPE_EXISTS_FLG:"No", children: [

      {DATALEVEL:

      "Arlington Plant", EFF_DT:"04-25-2011", END_DT:"12-25-2025", ORD:"SMTWTFS", RECV_WKS:"1234", LOAD_OFFSET:"24", TIME_FENCE:"10", TRANS_LEAD_TM:"1"},

      {DATALEVEL:

      "DBS MFG Plant", EFF_DT:"04-25-2011", END_DT:"12-25-2025", ORD:"SMTWTFS", RECV_WKS:"1234", LOAD_OFFSET:"24", TIME_FENCE:"10", TRANS_LEAD_TM:"1"},

      ]

      }

      ]}

       

      ]);

       

       

       

      private function init():void {

       

      var lh:MenuLeafHandler = new MenuLeafHandler();

       

      var t:Traversal = new Traversal(lh);

      t.traverseAndGetHandler(grid.groupedColumns);

      arr = lh.getArray();

      }

       

      private function menu_change(evt:MenuEvent):void {

       

      var lh:HideShowHandler = new HideShowHandler(evt.item.label);

       

      var t:Traversal = new Traversal(lh);

      t.traverseAndGetHandler(grid.groupedColumns);

      lh.getLeaf().visible = popupmenubutton1.dataDescriptor.isToggled(evt.item);

      }

       

      public function editCell(evt:Event):void {

       

      var selCells:Array = grid.selectedCells;

       

      var s:String = evt.toString();

      }

       

       

      private function showPopUp(evt:Event):void {

       

       

      var strvar:String = evt.target.selectedItem.toString();

       

      if (evt.currentTarget.selectedCells[0].columnIndex == 7) {

       

      var minIncCalcFlagPopUp:MinIncCalcFlagPopUp = new MinIncCalcFlagPopUp();

      PopUpManager.addPopUp(minIncCalcFlagPopUp,

      this,true);

      PopUpManager.centerPopUp(minIncCalcFlagPopUp)

      }

      else if (evt.currentTarget.selectedCells[0].columnIndex == 8) {

       

      var tagPopUp:TagPopUp = new TagPopUp();

      tagPopUp.init();

       

      var tagPanel:Panel = tagPopUp.panel;

      PopUpManager.addPopUp(tagPanel,

      this,true);

      PopUpManager.centerPopUp(tagPanel);

      }

      else if (evt.currentTarget.selectedCells[0].columnIndex == 9) {

       

      var dlyAllocPopUp:DlyAllocPopUp = new DlyAllocPopUp();

      PopUpManager.addPopUp(dlyAllocPopUp,

      this,true);

      }

      else if (evt.currentTarget.selectedCells[0].columnIndex == 10) {

       

      var fcstPopUp:FcstPctPopUp = new FcstPctPopUp();

      PopUpManager.addPopUp(fcstPopUp,

      this,true);

      PopUpManager.centerPopUp(fcstPopUp);

      }

      else if (evt.currentTarget.selectedCells[0].columnIndex == 19) {

       

      var ovrdeRecvDaysPopUp:OvrdeRecvDaysPopUp = new OvrdeRecvDaysPopUp();

      PopUpManager.addPopUp(ovrdeRecvDaysPopUp,

      this,true);

      PopUpManager.centerPopUp(ovrdeRecvDaysPopUp)

       

      }

       

      //}

      }

       

      ]]>

       

      </fx:Script>

       

       

      <s:VGroup height="100%" width="100%" gap="10" paddingLeft="10" paddingRight="10" paddingTop="10" paddingBottom="10" >

       

      <s:Label mouseMove="mouseMoveHandler(event);" text="Item Settings" fontWeight="bold" textAlign="center" color="#04498F" fontSize="18" fontStyle="normal" horizontalCenter="22" alpha="1.0"/>

       

      <s:HGroup width="100%">

       

      <mx:PopUpMenuButton id="popupmenubutton1" x="10" y="10" label="Hide/Show Columns" dataProvider="{arr}" itemClick="menu_change(event)"/>

       

      <mx:Spacer width="100%" />

       

      <s:Button label="Run Item Settings Analyzer" color="0x000000" />

       

      <s:Button label="Save..." color="0x000000" />

       

      <s:Button label="Export..." color="0x000000" />

       

      <s:Button id="maxRestoreButton" label="Maximize" click="Maximize_clickHandler(event)" color="0x000000" />

       

      </s:HGroup>

       

       

      <mx:AdvancedDataGrid id="grid"

      width="

      100%" height="100%"

      rowHeight="

      20"

      paddingBottom="

      0"

      paddingTop="

      0"

      wordWrap="

      false"

      editable="

      true"

      enabled="

      true"

      displayItemsExpanded="

      true"

      allowMultipleSelection="

      true"

      allowDragSelection="

      true"

      selectionMode="

      multipleCells"

      headerSortSeparatorSkin="

      mx.skins.ProgrammaticSkin"

      verticalScrollPolicy="

      on"

      horizontalScrollPolicy="

      on"

      itemClick="showPopUp(event)"

      >

       

      <mx:dataProvider>

       

      <mx:HierarchicalData source="{dpHierarchy}"

      childrenField="

      children"/>

       

      </mx:dataProvider>

       

      <mx:groupedColumns>

       

      <mx:AdvancedDataGridColumn dataField="DATALEVEL"

      headerText="

      Destination/Product/Source"

      fontWeight="

      bold"

      width="

      200"

      editable="

      false"

      textDecoration="

      underline"/>

       

      <mx:AdvancedDataGridColumn dataField="PROD_DESCP"

      headerText="

      Prod Descp"

      editable="

      false"

      width="

      100"/>

       

       

      <mx:AdvancedDataGridColumnGroup headerText="Product-Level Attributes" fontWeight="bold" textDecoration="underline">

       

      <mx:AdvancedDataGridColumn dataField="BDC"

      headerText="

      BDC"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="BDC_SUBGRP"

      headerText="

      BDC SubGrp"

      editable="

      true"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="PROD_STAT"

      headerText="

      Prod Status"

      editable="

      true"

      itemEditor="

      mx.controls.TextArea"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="UOM"

      headerText="

      UOM"

      editable="

      false"

      width="

      50"/>

       

      <mx:AdvancedDataGridColumn dataField="EACHES_PER_UOM"

      headerText="

      Eaches/UOM"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="MIN_INC_FLG"

      headerText="

      Min/Inc Flag"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="TAG"

      headerText="

      Tags"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="DLY_ALLOC"

      headerText="

      Daily Alloc"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="FCST_PCT"

      headerText="

      Fcst Pct"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="SKU_MFG_SUBCLS"

      headerText="

      Sku Mfg Subcls"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="OVRD_PROD_FLG"

      headerText="

      Override Prod Flg"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="ON_OFF_LINE"

      headerText="

      On/Off Line"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="PROD_LEAD_TM"

      headerText="

      Produced Lead Time"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="NON_PROD_LEAD_TM"

      headerText="

      Non-Produced Lead Time"

      editable="

      false"

      width="

      100"/>

       

      <mx:AdvancedDataGridColumn dataField="RECIPE_EXISTS_FLG"

      headerText="

      Recipe"

      editable="

      false"

      width="

      100"/>

       

      </mx:AdvancedDataGridColumnGroup>

       

      <mx:AdvancedDataGridColumnGroup headerText="Source-Level Attributes" fontWeight="bold" textDecoration="underline">

       

       

      <mx:AdvancedDataGridColumn dataField="EFF_DT"

      headerText="

      Eff Dt"

      editable="

      false"

      width="

      75"/>

       

      <mx:AdvancedDataGridColumn dataField="END_DT"

      headerText="

      End Dt"

      editable="

      false"

      width="

      75"/>

       

      <mx:AdvancedDataGridColumn dataField="ORD"

      headerText="

      Ovrde Recv Days"

      editable="

      false"

      width="

      75"/>

       

      <mx:AdvancedDataGridColumn dataField="RECV_WKS"

      headerText="

      Recv Wks"

      editable="

      true"

      width="

      75"/>

       

       

      <mx:AdvancedDataGridColumn dataField="LOAD_OFFSET"

      headerText="

      Load Offset"

      editable="

      true"

      width="

      75"/>

       

      <mx:AdvancedDataGridColumn dataField="TIME_FENCE"

      headerText="

      Time Fence"

      editable="

      true"

      width="

      75"/>

       

      <mx:AdvancedDataGridColumn dataField="TRANS_LEAD_TM"

      headerText="

      Trans Lead Time"

      sortable="

      false"

      editable="

      true"

      width="

      75"/>

       

       

      </mx:AdvancedDataGridColumnGroup>

       

      </mx:groupedColumns>

       

      </mx:AdvancedDataGrid>

       

      </s:VGroup>

      </mx:VBox>

       

       

        • 1. Re: AdvancedDataGrid selectedItem is null
          ssardar Level 1

          Without implementing your code

           

          try:

           

           

          evt.currentTarget.selectedItem.toString() if your data provider is an arrayCollection of strings, if it contains objects then

           

          evt.currentTarget.selectedItem.AttributeName.toString()

          • 2. Re: AdvancedDataGrid selectedItem is null
            checker2505 Level 1

            That is exactly what I am doing but evt.currentTarget.selectedItem is null.

            • 3. Re: AdvancedDataGrid selectedItem is null
              ssardar Level 1

              also try using "click" instead of itemClick on

              your advanceddatagrid.

               

              I wrote a simple example:

               

               

              <?xml version="1.0" encoding="utf-8"?>

              <mx:Application

               

               

              xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" >

               

               

               

              <mx:Script>

              <![CDATA[

               

              import mx.charts.series.ColumnSeries;

               

              import mx.charts.CategoryAxis;

               

              import mx.charts.LinearAxis;

               

              import mx.collections.ArrayCollection;

               

              import mx.controls.Alert;

               

               

               

              private function handleClick(evt:Event):void {

               

               

              Alert.show(evt.currentTarget.selectedItem.Month.toString());

               

              }

               

              [

              Bindable]

               

              var months = new ArrayCollection( [

              { Month:

              "February", Day:"Tuesday", Year:"2011"},

              { Month:

              "March", Day:"Friday", Year:"2012"},

              { Month:

              "April", Day:"Monday", Year:"2013"}]);

               

                

               

              ]]>

               

              </mx:Script>

               

              <mx:AdvancedDataGrid x="155" y="358" id="adg1" designViewDataType="tree" dataProvider="{months}" click="handleClick(event)">

               

              <mx:columns>

               

              <mx:AdvancedDataGridColumn width="85" headerText="Column 1" dataField="Month"/>

               

              <mx:AdvancedDataGridColumn width="35" headerText="Column 2" dataField="Day"/>

               

              <mx:AdvancedDataGridColumn width="35" headerText="Column 3" dataField="Year"/>

               

              </mx:columns>

               

              </mx:AdvancedDataGrid>

               

               

               

               

               

               

               

               

               

              </mx:Application>

              • 4. Re: AdvancedDataGrid selectedItem is null
                ssardar Level 1

                although itemclick does work in my example too (I'm just in the habit of using click)

                 

                I'll implement your posted code later today if you still don't have it working.