6 Replies Latest reply on Jul 2, 2009 10:38 PM by 435.mahesh

    how to update record?

    435.mahesh Level 1

      Hi,

      i have send screen shot for my requirement,

      Datagrid contains edit buttons(i used itemrender).

      When i clicked on the edit button in corresponding record,the data corresponding record

      will be populated in left screen.

      Here How can we pass id of that particular record to the button? or

      how can i meet this requirement?

       

       

       

      Thanking You

      D.Mahesh Babu

        • 1. Re: how to update record?
          Zolotoj Level 3

          You need to make sure that when you click on Edit button the grid gets a row the button is in selected.

          If dataProvider has a field ID then grid.selectedItem.ID would be available in the button's click.

           

          HTH

          • 2. Re: how to update record?
            435.mahesh Level 1

            Thanks for response.

            I got all the record ids,but how can i passed that id to function when i clicked on particular row edit

            button?

             

             

            Regrds

            D.Mahesh babu

            • 3. Re: how to update record?
              Zolotoj Level 3

              Add a click listener to your custom item renderer:

              addEventListener("click", onClick);
              
              // then here you should have data available
              private
              
              
               function onClick(e:Event):void{
              
                   trace(DataGrid(listData.owner).selectedItem.ID);
              
              } 
              
              
              

              • 4. Re: how to update record?
                sri harsha namala Level 2

                Hi

                            You can Dispatch Event when DataGrid row is Selected , If you want to Use Item Renderes inside the component  Dispatch Event.

                i have similar type of code that will show you the values when u click Button in Alert. Go through the code once

                 

                Sample.mxml

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" creationComplete="init()">
                <mx:Script>
                    <![CDATA[
                        import mx.collections.ArrayCollection;
                        [Bindable]
                        public var arr:ArrayCollection=new ArrayCollection();
                        private function init():void
                        {
                            for(var i:int=0;i<10;i++)
                            {
                                arr.addItem({A:Math.random()*i,B:Math.random()*i,C:i});
                            }
                        }
                    ]]>
                </mx:Script>
                    <mx:DataGrid width="50%" height="50%" dataProvider="{arr}">
                        <mx:columns>
                            <mx:DataGridColumn dataField="A" />
                            <mx:DataGridColumn dataField="B" />
                            <mx:DataGridColumn dataField="C" itemRenderer="sample.SampleButton" rendererIsEditor="true"/>
                        </mx:columns>
                    </mx:DataGrid>
                    </mx:Application>

                 

                SampleButton.mxml

                <?xml version="1.0" encoding="utf-8"?>
                <mx:Canvas xmlns:mx="http://www.adobe.com/2006/mxml" width="100%" height="100%" >
                    <mx:Button id="btn"  label="Button{data.C}" click="getValues()"/>
                    <mx:Script>
                        <![CDATA[
                            import mx.controls.Alert;
                            private function getValues():void
                            {
                                Alert.show("A ->"+data.A+" ,B->"+data.B);
                            }
                        ]]>
                    </mx:Script>
                </mx:Canvas>

                • 5. Re: how to update record?
                  sri harsha namala Level 2

                  HI,

                          Simply you can dispatch Event and you can show the Values in the Form , Once go through this code

                   

                            <?xml version="1.0" encoding="utf-8"?>
                  <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="horizontal" creationComplete="init()">
                  <mx:Script>
                      <![CDATA[
                          import mx.controls.Alert;
                          import mx.collections.ArrayCollection;
                          [Bindable]
                          public var arr:ArrayCollection=new ArrayCollection();
                          private function init():void
                          {
                              dg.addEventListener(MouseEvent.CLICK,mouseClicked);
                              for(var i:int=0;i<10;i++)
                              {
                                  arr.addItem({A:Math.random()*i,B:Math.random()*i,C:i});
                              }
                          }
                          private function mouseClicked(event:MouseEvent):void
                          {
                              Alert.show("A:"+dg.selectedItem.A+ "B :"+dg.selectedItem.B);
                          }
                      ]]>
                  </mx:Script>
                      <mx:DataGrid id="dg" width="50%" height="50%" dataProvider="{arr}" >
                          <mx:columns>
                              <mx:DataGridColumn dataField="A" />
                              <mx:DataGridColumn dataField="B" />
                              <mx:DataGridColumn dataField="C" />
                          </mx:columns>
                      </mx:DataGrid>
                     
                  </mx:Application>