5 Replies Latest reply on Sep 7, 2009 5:29 AM by _Natasha_

    add multiple linkbuttons in a datagridcolumn

    Sharadananda_Mondal

      Hi friends,

      I am facing challenges in adding multiple linkbuttons in a datagrid column and unable to solve until now. the requirement is to display data in a table having two columns date and books.Corresponding to each date there are multiple books. clicking on each book icon will let the user download the pdf format of selected book. the books names are arraycollection. I tried datagrid column but then cant add generate linkbuttons iteratively for it, besides tried using repeater needs to give dataprovider which is also giving errors.

       

      Sample Code:

      <mx:Script>
                <![CDATA[
                   import mx.collections.ArrayCollection;             
                   import mx.controls.Alert;
                   [Bindable]
                   private var arr:ArrayCollection;
                   private function init():void
                  {
                    arr=new ArrayCollection([{date:"05july", books:"book1.xls"},{date:"6july", books:"book2.pdf, book3.xls, book4.xls, book5.xls"}]);
                   
                  }]]>

      <mx:DataGrid id="dataGrid" dataProvider="{arr}" editable="true">
                <mx:columns>
                   <mx:DataGridColumn  dataField="date" headerText="Result Date" editable="false"/>
                   <mx:DataGridColumn  headerText="Books" editable="false" >
                     <mx:itemRenderer>
                          <mx:Component>                       
                               <mx:Repeater id="rp" dataProvider="{arr}">                            
                                  <mx:LinkButton label="{String(rp.currentItem.books)}"/>
                               </mx:Repeater>                                    
                          </mx:Component>
                     </mx:itemRenderer>
                   </mx:DataGridColumn>
                </mx:columns>
           </mx:DataGrid>

      </mx:Application>

      Really appreciate your help.

        • 1. Re: add multiple linkbuttons in a datagridcolumn
          _Natasha_ Level 4

          Hi,

          the first you can use LinkBar if you have multiple LinkButtons - it's easier.

           

          the second problem is that you have only one string for all your books. It's not good.

          Can you create a books not a string, nor array. Something like this:

           

          arr=new ArrayCollection([{date:"05july", books:["book1.xls"]},{date:"6july", books:["book2.pdf", "book3.xls", "book4.xls", "book5.xls"]}]);

           

          If you will have this structure you can use

          <mx:itemRenderer>
                              <mx:Component>                       
                                      <mx:LinkBar dataProvider="{data.books}"/>
                              </mx:Component>
                         </mx:itemRenderer>

          1 person found this helpful
          • 2. Re: add multiple linkbuttons in a datagridcolumn
            satoshi.ara Level 1

            Hi,

             

            I din't really get it, what you want to do.

            But first of all, the source you shown wont be compiled correct.

            You cannot define an "id" attribute to the root element of the itemRenderer component.

            The following will be at least shown, but I don't know what I can help you any farther.

             

            <mx:DataGrid id="dataGrid" dataProvider="{arr}" editable="true">
                      <mx:columns>
                         <mx:DataGridColumn  dataField="date" headerText="Result Date" editable="false"/>
                         <mx:DataGridColumn  headerText="Books" editable="false" >
                           <mx:itemRenderer>
                                <mx:Component>
                                    <mx:Canvas horizontalScrollPolicy="off">
                                        <mx:Repeater id="rp" dataProvider="{data}">
                                            <mx:LinkButton label="{String(rp.currentItem.books)}"/>
                                        </mx:Repeater>
                                    </mx:Canvas>
                                </mx:Component>
                           </mx:itemRenderer>
                         </mx:DataGridColumn>
                      </mx:columns>
                </mx:DataGrid>

            • 3. Re: add multiple linkbuttons in a datagridcolumn
              Sharadananda_Mondal Level 1

              Hi,

              Thanks.Your suggestions really helped me.

              • 4. Re: add multiple linkbuttons in a datagridcolumn
                Sharadananda_Mondal Level 1

                Hi,

                Can you advice me on why I cannot get all the books displayed in the datagrid as it is showing equal no of records for all the dates. For example if 05th july has the books and 06th july has two books then for both the dates it displays two books only.

                • 5. Re: add multiple linkbuttons in a datagridcolumn
                  _Natasha_ Level 4

                  This may be because Array don't dispatch change event. You can try to override function set data(value:Object):void for renderer.