8 Replies Latest reply on Sep 14, 2008 11:01 PM by ajesing

    DataGrid.selectedItem Doubt

    ajesing
      Hello,

      I have defined <mx:DataGrid and <mx:DataGridColumn in main.mxml and I am calling itemRenderer=ActionsControls where ActionsControls is defined in ActionsControls.mxml file.

      I want get the current row values, so I am using DataGrid.selectedItem. My problem is since how do I refer the DataGrid referred in main.mxml from ActionsControls.mxml, because my click event of the ActionControl is in ActionsControls.mxml.

      Could someone provide a solution for this problem?

      Thanks
        • 1. Re: DataGrid.selectedItem Doubt
          atta707 Level 2
          If I understand you question correctly, you want to get a reference to the DataGrid from one of it's renderers? If that's so, try this:

          var dg:DataGrid = this.listData.owner as DataGrid;

          Every renderer, both drop-in or custom, has to have listData property and its owner property refers to the DataGrid that's hosting this renderer.

          ATTA
          • 2. Re: DataGrid.selectedItem Doubt
            ajesing Level 1
            Thanks for the reply.

            My requirement is is from ActionControls.mxml (where I defined the buttons) I would like to get the DataGrid.selectedItem.TestValueDate(is the name of the dataField). So when I click the button in the actioncontrol, I would get the value of the current row.

            btw
            I didn't understand as what is listData?
            var dg:DataGrid = this.listData.owner as DataGrid;

            Your help is highly appreciated.
            • 3. Re: DataGrid.selectedItem Doubt
              atta707 Level 2
              Is action control a custom item renderer for one of the columns in your grid?

              if the answer it yes, then it should have a listData property.

              Just override the "set data(value:Object)" function either in MXML Script tag or in plain ActionScript class:

              override public function set data(value:Object) : void {
              // value represents the current row grid is going to paint
              super.data = value;
              Alert.show(value.TestValueDate) // this should should an alert with the value of the field.
              }

              if it doesn't work please show some of your code.
              • 4. DataGrid.selectedItem Doubt
                ajesing Level 1
                Hi,

                That didn't work, attached is part of main.mxml and ActionControls.mxml.

                In the ActionControls.mxml there is an edit button so when I click edit button, I should I get the current row values which I am trying to get using selectedItem.

                Thanks a lot
                • 5. Re: DataGrid.selectedItem Doubt
                  atta707 Level 2
                  In your test function:

                  private function test(str:String):void{
                  Alert.show(this.data.TestValueDate);
                  }

                  or a longer way would be:

                  private function test(str:String):void{
                  var dg:DataGrid = this.listData.owner as DataGrid;
                  var si:Object = dg.selectedItem;
                  if (si) {
                  Alert.show(si.TestValueDate);
                  }
                  }

                  I'll be surprised if these don't work!

                  ATTA


                  • 6. Re: DataGrid.selectedItem Doubt
                    ajesing Level 1
                    I tried the first approach and it worked.

                    Thanks a lot.

                    I assume these are only ways I could get the current row values!

                    Regards
                    • 7. Re: DataGrid.selectedItem Doubt
                      atta707 Level 2
                      second approach should work as well! You might want to study more about custom renderers and how the 'data' property is used used to pass the current to the renderer.

                      ATTA
                      • 8. Re: DataGrid.selectedItem Doubt
                        ajesing Level 1
                        Thanks atta707

                        I am a newbie in Flex, in the process of learning.

                        Regards