8 Replies Latest reply on Jun 2, 2011 10:57 AM by Pankaj@flex

    How to access components inside a itemerederer(datagridColumn)

    flex_things

      Hi to all,

      In my recent appilcation Iam using a button inside a datagridColum by itemerenderer.

       

      <columns:ExtendedDataGridColumn
                                                  
                  >
                      <columns:itemRenderer>
                          <mx:Component>
                              <mx:HBox width="50" horizontalAlign="center">
                                  <mx:Button width="16" height="20"                                                                         
                                      visible="true"
                                      id= "editButtonId"
                                      toolTip="Bearbeiten"
                                     
                                      click="outerDocument.editButtonClicked(event)"         

                                      />
                              </mx:HBox>                       
                          </mx:Component>
                      </columns:itemRenderer>
      </columns:ExtendedDataGridColumn>

       

      By using "outDoucument" I can able to access method in the parent appliaction.

      My question how to access button Id(editButtonId) in the parent.

       

      thanks in adavance

        • 1. Re: How to access components inside a itemerederer(datagridColumn)
          flex4 Level 2

          Hi

           

                     The code that u have achieved here is wrong because id property is not allowed in component tag... you are using inline itemrenderers so that will not work properly and it is not a good coding standards.. u can use this in simple and applications... if ur item renderer will not going to work any thing..

           

           

                  if  ur item renderer having some functionality create saperatate item renderer and use that component in ur datagrid then u can access the components inside the itemrenderer ..

           

                         I am posting u sample code  here

           

                             create seperate item renderer as per example MyComItemRenderer.mxml

           

                               <mx:HBox width="50"  horizontalAlign="center">
                                       <mx:Button width="16"  height="20"                                                                           
                                          visible="true"
                                           id= "editButtonId"
                                           toolTip="Bearbeiten"
                                         
                                           click="outerDocument.editButtonClicked(event)"         
                                           />
                                  </mx:HBox>   

           

                                   and use this itemrenderer in the column in datagrid...

           

           

                                        <columns:ExtendedDataGridColumn itemRenderer="..../MyComItemRenderer.mxml"/>

           

          this will help u .. ..

          • 2. Re: How to access components inside a itemerederer(datagridColumn)
            Subeesh Arakkan Level 4

            If it is the first column, you can use the itemToItemRenderer method of the dataGrid.

             

            var renderer:Object = dataGrid.itemToItemRenderer(dg.selectedItem);
            var button:Button = renderer.editButtonId as Button;
            

             

            However, why do yo u want to access the button in the renderer from outside ?.

            • 3. Re: How to access components inside a itemerederer(datagridColumn)
              flex_things Level 1

              thanks for reply..

              Even throughif I write as u said

              itemRenderer="..../MyComItemRenderer.mxml"/

               

              How should I access the properties of button in the parent.

              • 4. Re: How to access components inside a itemerederer(datagridColumn)
                flex_things Level 1

                thanks for reply.

                 

                depending upon the permission of the user.

                 

                to make sometimes button visible or not.

                • 5. Re: How to access components inside a itemerederer(datagridColumn)
                  Subeesh Arakkan Level 4

                  It is better to do all those stuff inside the renderer itself as the renderers get recycled during different events like dataprovier change, scroll, sort, resize etc

                   

                  inside the renderer you have the access to the actual data which is the row item.

                   

                  to disable the Button you could do something like

                   

                  <mx:Button enabled="{data.hasPermission}"/>

                   

                  if you need to apply some other logic for setting the permission, you can override the set data method

                  • 6. Re: How to access components inside a itemerederer(datagridColumn)
                    flex_things Level 1

                    thanks for reply.

                    but I need to access buttonId(editButtonId) in parent, then my problem will be solved.

                    • 7. Re: How to access components inside a itemerederer(datagridColumn)
                      flex4 Level 2

                      Hi

                       

                         In item renderers use Application.application."ur button id ''; this will get ur button id in the parent application to itemrenderer....k

                      1 person found this helpful
                      • 8. Re: How to access components inside a itemerederer(datagridColumn)
                        Pankaj@flex

                        Hi Guys,

                        I have just joined adobe forums. I have a question. I have two mxml one is which is my main application and another one is itemRenderer of List which is in my

                        Main application. Now i want to access button component from my main application which is inside itemRenderer.

                        I will be very thankful if any of you give me the solution of this problem.

                        Thanks in advance!