1 Reply Latest reply on Sep 28, 2010 9:07 AM by rootsounds

    Datagrid, with checkbox to copy data

    djh88ukwb Level 1

      Hello all.

       

      I am trying to create a datagrid component, that adds a checkbox into the last column of a table.  The checkbox when clicked should then copy all the data for that row, and save it into a tempory array, so i can use it later in the application.

       

      My code is as follows

       

      <?xml version="1.0" encoding="utf-8"?>
      <s:Application xmlns:fx="http://ns.adobe.com/mxml/2009"
                      xmlns:s="library://ns.adobe.com/flex/spark"
                      xmlns:mx="library://ns.adobe.com/flex/mx">
          <fx:Script>
              <![CDATA[
                  import mx.events.IndexChangedEvent;
                  import mx.collections.ArrayCollection;
                  import mx.controls.Alert;
                 
                 
                 
                  [Bindable]
                  private var ac:ArrayCollection=new ArrayCollection([
                      {Name: "John", Score:"25", rating:"3", sel: false},
                      {Name: "Joe", Score:"45", rating:"5", sel: false},
                      {Name: "Jill", Score:"35", rating:"2", sel: false}])
                 
                 
              ]]>
          </fx:Script>
         
          <mx:DataGrid id="dg"
                       dataProvider="{ac}" x="10" y="10" width="596" height="356">
              <mx:columns>
                  <mx:DataGridColumn headerText="Name" dataField="Name"/>
                  <mx:DataGridColumn headerText="Score" dataField="Score" width="50"/>
                  <mx:DataGridColumn headerText="Rating" dataField="rating" itemRenderer="rate" width="100"/>
                  <mx:DataGridColumn headerText="Select" id="col2" editorDataField="selected" rendererIsEditor="true" dataField="data.sel" width="50">
                          <mx:itemRenderer>
                              <fx:Component>   
                                  <mx:CheckBox selected="{data.sel}" change="data.sel=selected" paddingLeft="20">
                                  </mx:CheckBox>
                              </fx:Component>
                          </mx:itemRenderer>
                  </mx:DataGridColumn>
                 
              </mx:columns>
             
          </mx:DataGrid>


      </s:Application>

       

      Basically the checkbox in the last column needs to be able to when changed to selected==true, copy all the data for that row, the Name, Score and rating, and save it into an array so tha ti can use it later.

       

      Thanks in advance