4 Replies Latest reply on Feb 11, 2011 7:55 AM by madhooper

    how to get the index for itemrenders

    madhooper Level 1

      I have an itemrender with a button. I'd like to disable the button for the first and last object in my itemrenderer (list). Can any provide a simple example how to accomplish this task?

       

      Thanks for your assistance.

        • 1. Re: how to get the index for itemrenders
          John Hall Level 4

          Not sure of the specifics but I assume you have a dataProvider and you could certaintly do a check to see if it's element 0 or dp.length-1.

          • 2. Re: how to get the index for itemrenders
            BhaskerChari Level 4

            Hi madhooper,

             

            You can try this way..make use of Boolean variable..

             

            <?xml version="1.0"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" >
               
                <mx:Script>
                    <![CDATA[
                      import mx.collections.ArrayCollection;
                   
                      [Bindable]
                      private var initDG:ArrayCollection = new ArrayCollection([
                        {Artist:'Pavement1', Album:'Slanted and Enchanted', Price:11.99, IsEnabled:false},
                        {Artist:'Pavement2', Album:'Brighten the Corners', Price:178.99, IsEnabled:true},
                        {Artist:'Pavement3', Album:'Enlighten the Corners', Price:174.99, IsEnabled:true},
                        {Artist:'Pavement4', Album:'Borade the Corners', Price:431.99, IsEnabled:true},
                        {Artist:'Pavement5', Album:'Corners of Edges', Price:221.99, IsEnabled:true},
                        {Artist:'Pavement6', Album:'Maniacal Palace', Price:32.99, IsEnabled:false}
                      ]);           
                    ]]>
                </mx:Script>

                <mx:Panel paddingTop="10" paddingBottom="10"
                    paddingLeft="10" paddingRight="10">

                    <mx:DataGrid id="myGrid" dataProvider="{initDG}"
                        width="100%" editable="true">
                        <mx:columns>
                            <mx:DataGridColumn dataField="Artist" resizable="true"/>
                            <mx:DataGridColumn dataField="Album" resizable="true"/>
                            <mx:DataGridColumn dataField="Price" resizable="true"/>
                            <mx:DataGridColumn editable="false">
                             <mx:itemRenderer>
                              <mx:Component>
                               <mx:Button enabled="{data.IsEnabled}" label="Edit" />
                              </mx:Component>
                             </mx:itemRenderer>
                            </mx:DataGridColumn>
                        </mx:columns>      
                    </mx:DataGrid> 
                </mx:Panel>   
            </mx:Application>

             

             

            Thanks,

            Bhasker

            • 3. Re: how to get the index for itemrenders
              madhooper Level 1

              ok

               

              I have a parent componet that I load the item renderers in.

               

              I count the number of children componets i.e. parentcomponent.numchildren

               

              I'd like to disable a button in the first and last child.

               

              Is there a simple way to get the index of child components or am I going about this the wrong way?

              • 4. Re: how to get the index for itemrenders
                madhooper Level 1

                ok

                 

                I have a parent componet that I load the item renderers in.

                 

                I count the number of children componets i.e. parentcomponent.numchildren

                 

                I'd like to disable a button in the first and last child.

                 

                Is there a simple way to get the index of child components or am I going about this the wrong way?