7 Replies Latest reply on Sep 22, 2010 3:07 AM by Leslie_Pinto

    Making a Datagrid with more than one itemrendrer

    vineet osho Level 1

      Hello Friends

                              is there any way to make a custom datagrid having more than one itemrendrer.i meanto say i want combobox on first row of data grid and text area on third row and list on some other row of same column.i mean on same datafield with diffrent rendring component.is it possible?.if yes than please explain.

       

       

      Regards

      Vineet Osho.

        • 2. Re: Making a Datagrid with more than one itemrendrer
          Leslie_Pinto Level 1

          Here is a simpler sample:

          <?xml version="1.0" encoding="utf-8"?>

          <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute"

          creationComplete="populateData()" xmlns:display="flash.display.*">

          <mx:Script>

          <![CDATA[

          import mx.collections.ArrayCollection;

           

          [Bindable]private var arr:ArrayCollection

           

          private function populateData():void

          {

          //Create an arraycollection

          arr = new ArrayCollection()

          //Loop to create 10 records

          for(var i:int=0;i<10;i++)

          {

          //Create an object to insert into the array collection

          var obj:Object = {col1:i, col2:i,col3:i}

          //Add the object to array collection

          arr.addItem(obj)

          }

          }

           

           

           

           

          ]]>

          </mx:Script>

           

          <mx:DataGrid x="136" y="90" dataProvider="{arr}" >

          <mx:columns>

          <mx:DataGridColumn headerText="Column 1" dataField="col1" >

          <mx:itemRenderer>

          <mx:Component>

          <mx:ComboBox>

          <mx:String>Hi</mx:String>

          <mx:String>Vineeth</mx:String>

          </mx:ComboBox>

          </mx:Component>

          </mx:itemRenderer>

          </mx:DataGridColumn>

          <mx:DataGridColumn headerText="Column 2" dataField="col2"/>

          <mx:DataGridColumn headerText="Column 3" dataField="col3">

          <mx:itemRenderer>

          <mx:Component>

          <mx:TextArea text="ur text" />

          </mx:Component>

          </mx:itemRenderer>

          </mx:DataGridColumn>

          </mx:columns>

          </mx:DataGrid>

           

           

           

          </mx:Application>

          1 person found this helpful
          • 3. Re: Making a Datagrid with more than one itemrendrer
            vineet osho Level 1

            Hi liesi

                        Thanks for your quick reply.but your exaple creats combobox or text field in diffrent columns.i want combobox in first row of same column and text area in 2nd row of same coumn of data gris.hope u getting my point now.Yes we have a key node in arraycolllection on the basis of taht we can diffrentiate what component have to rendred on particular row of same column in our data grid.

            waiting for your reply.

             

            Thanks and regards

               Vineet Osho

            • 4. Re: Making a Datagrid with more than one itemrendrer
              Anitha Selvaraj Level 2

              Hi,

               

              I am not sure whether it is possible to display different item renderers in each row. But you can try one thing. Create a item renderer component with all sorts of displays you want, say checkbox, combo box etc., and make only the required component's visibility as true or false based on the key you have.

               

              For eg,

               

              CustomRenderer.mxml contains mx:Checkbox, mx:ComboBox. On first row of a particular column, you want to display Checkbox alone. In that case, inside the set data() method, make the visibility of the checkbox as true and the visibility of combo box as false.

               

              Hope this helps.

               

              Regards,

              Anitha

              1 person found this helpful
              • 5. Re: Making a Datagrid with more than one itemrendrer
                vineet osho Level 1

                Thanks Anitha

                                         i think thi siwil work but i have one thing to ask.how can i call setdata Function every time.i mean to say that setdat function have to call every time when that custom component rendere in my data grid.is this possible?Pleaase reply

                 

                Thanks In Advance

                    Vineet osho

                 

                 

                http://forums.adobe.com/people/Anitha%20Selvaraj

                • 6. Re: Making a Datagrid with more than one itemrendrer
                  vineet osho Level 1

                  hi Anitha

                                     Thanks for your support.It works for me.

                   

                   

                  Regards

                  Vineet osho

                  • 7. Re: Making a Datagrid with more than one itemrendrer
                    Leslie_Pinto Level 1

                    Create a canvas customComponent with both ComboBox and Textarea which should show only one component based on the boolean flag. Your arraycollection should have a Boolean property lets say "IsCombo" with each of Objects.
                    If (IsCombo == true)

                    {

                         myComboBox.visible = true;

                         myTextArea.visible = false;

                    }

                    else

                    {

                        myComboBox.visible = false;

                         myTextArea.visible = true;

                    }

                     

                    it shows the combo or textrarea based on the proprty IsCombo .......If u confused feel free to ask