3 Replies Latest reply on Jan 9, 2011 7:06 AM by Don Kerr

    checkbox itemrenderer with XMLList

    Don Kerr Level 3

      When my dataProvider is an ArrayCollection, I use this approach to allow the user to select an item using a checkbox

       

      <mx:AdvancedDataGridColumn width="20" headerText="" 

         dataField="cb" editorDataField="selected" rendererIsEditor="true" editable="true">

      <mx:itemRenderer>

      <mx:Component>

      <mx:CheckBox   click="data.cb=!data.cb;"  selected="{data.cb}"/>

      </mx:Component>

      </mx:itemRenderer>

      </mx:AdvancedDataGridColumn>

       

      data.cb=!data.cb works great to toggle the data in the dataProvider.  I then save the changed cb values back to the database.

       

      I'd like to do something similar when my dataProvider is hierarchical XML

      myXML = event.result.Node  as XMLList;

       

       

       

      hierarchyDP = new HierarchicalData(myXML);

       

      I'd like the checkbox change to update the xml in my dataProvider so that I can later save the checked items to the database.

       

      It does not work if I just change it to data.@cb=!data.@cb

       

      <mx:AdvancedDataGridColumn width="20" headerText="" 

        dataField="@cb" editorDataField="selected" rendererIsEditor="true" editable="true">

      <mx:itemRenderer>

      <mx:Component>

      <mx:CheckBox   click="data.@cb=!data.@cb;"  selected="{data.@cb}"/>

      </mx:Component>

      </mx:itemRenderer>

      </mx:AdvancedDataGridColumn>

       

       

      How do I update the cb property ('true' or 'false') in the current Node inside the dataProvider so I can save the changed cb values back to database?  In other words, if the xml contains cb='true', and the user unchecks the box for the current data, how do I change cb='false';

       

      Thanks,

      Don Kerr

        • 1. Re: checkbox itemrenderer with XMLList
          Wrataxas Level 2

          Maybe data.@cb is a String and you need to convert it to a Boolean before negating it?

           

          !(data.@cb == "true")

           

          or perhaps

           

          ! Boolean( data.@cb )

          1 person found this helpful
          • 2. Re: checkbox itemrenderer with XMLList
            Gregory Lafrance Level 6

            Sometimes Boolean in itemRenderers are strange. This code answers your question:

             

            <?xml version="1.0" encoding="utf-8"?>
            <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml"
              creationComplete="init();">
              <mx:Script>
                <![CDATA[
                  import mx.collections.XMLListCollection;
                  
                  [Bindable] public var xlc:XMLListCollection;
                  
                  private function init():void{
                    xlc = new XMLListCollection(xmllist);
                    trace(xlc.length);
                  }
                ]]>
              </mx:Script>
              <mx:XMLList id="xmllist" xmlns="">
                 <item cb='true'/>  
                <item cb='false'/>  
                <item cb='false'/>  
                <item cb='true'/>  
                <item cb='true'/>      
              </mx:XMLList>
              <mx:AdvancedDataGrid dataProvider="{xlc}" width="100">
                <mx:columns>
                  <mx:AdvancedDataGridColumn width="80"  
                    dataField="@cb">
                    <mx:itemRenderer>
                      <mx:Component>
                        <mx:CheckBox selected="{data.@cb=='true'?true:false}" 
                          click="data.@cb=='true'?data.@cb='false':data.@cb='true';outerDocument.txt.text=outerDocument.xlc.toXMLString();"/>
                      </mx:Component>
                    </mx:itemRenderer>
                  </mx:AdvancedDataGridColumn>
                </mx:columns>
              </mx:AdvancedDataGrid>
              <mx:TextArea id="txt" width="100%" height="100%"/>
            </mx:Application>
            


            If this post answers your question or helps, please mark it as such. Thanks!

            http://www.stardustsystems.com
            Adobe Flex Development and Support Services

            • 3. Re: checkbox itemrenderer with XMLList
              Don Kerr Level 3

              Thanks Gregory!  This worked nicely.  I marked it as the answer!

               

              Appreciate the help.

               

              Don