8 Replies Latest reply on Aug 28, 2006 11:37 AM by Opsware_Jeff

    Stumped: Inline renderer for DataGridColumn with XML dataprovider

    Opsware_Jeff
      <?xml version="1.0"?>
      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" height="350" width="250">

      <mx:Script>
      <![CDATA[

      [Bindable]
      public var myTestArray:Array = [
      {label1:"/home", Test:true},
      {label1:"/bin", Test:false}];
      ]]>
      </mx:Script>

      <mx:XMLListCollection id="myTestXML">
      <mx:XMLList xmlns="">
      <partition label="C:\\" Test="true"/>
      <partition label="D:\\" Test="false"/>
      </mx:XMLList>
      </mx:XMLListCollection>

      <mx:DataGrid dataProvider="{myTestArray}" width="200" height="100" editable="true">
      <mx:columns>
      <mx:DataGridColumn headerText="myTestArray" dataField="Test" rendererIsEditor="true" editorDataField="selected">
      <mx:itemRenderer>
      <mx:Component>
      <mx:CheckBox selected="{data.Test}" label="{data.label1}"/>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      </mx:columns>
      </mx:DataGrid>

      <!-- Why doesn't this work with an XML data provider? -->
      <!-- What are my options for getting it to work with the XML data provider? -->
      <!-- I'd prefer a solution that is similar to the current code "framework" I've got. -->
      <mx:DataGrid dataProvider="{myTestXML}" width="200" height="100" editable="true">
      <mx:columns>
      <mx:DataGridColumn headerText="myTestXML" dataField="@Test" rendererIsEditor="true" editorDataField="selected">
      <mx:itemRenderer>
      <mx:Component>
      <mx:CheckBox selected="{data.Test}" label="{data.label1}"/>
      </mx:Component>
      </mx:itemRenderer>
      </mx:DataGridColumn>
      </mx:columns>
      </mx:DataGrid>
      </mx:Application>
        • 2. Re: Stumped: Inline renderer for DataGridColumn with XML dataprovider
          dwischusen Level 1
          Try:

          <mx:CheckBox selected="{data.@Test}" label="{data.@label}"/>
          • 3. Stumped: Inline renderer for DataGridColumn with XML dataprovider
            Opsware_Jeff Level 1
            Thanks, I tried that. It gives me a runtime error and doesn't even finish rendering the page. This seems like a really bad bug unless there is an easy way to coerce an XML structure into an array. Adobe, anyone home?

            Here is a better version of the code that I'm trying to get to work. My starting data is XML, so the Array version is just to show how the example code is supposed to work...

            <?xml version="1.0"?>
            <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" height="400" width="250">

            <mx:ArrayCollection id="myTestArray">
            <mx:Object dir="C:\\" Test="true"/>
            <mx:Object dir="D:\\" Test="false"/>
            </mx:ArrayCollection>

            <mx:XMLListCollection id="myTestXML">
            <mx:XMLList xmlns="">
            <partition>
            <dir>C:\\</dir>
            <Test>true</Test>
            </partition>
            <partition>
            <dir>D:\\</dir>
            <Test>false</Test>
            </partition>
            </mx:XMLList>
            </mx:XMLListCollection>

            <mx:XMLListCollection id="myTestXMLAttributes">
            <mx:XMLList xmlns="">
            <partition dir="C:\\" Test="true"/>
            <partition dir="D:\\" Test="false"/>
            </mx:XMLList>
            </mx:XMLListCollection>

            <!-- This works just fine with an Array data provider... -->
            <mx:DataGrid dataProvider="{myTestArray}" width="200" height="100" editable="true">
            <mx:columns>
            <mx:DataGridColumn headerText="myTestArray" dataField="Test" rendererIsEditor="true" editorDataField="selected">
            <mx:itemRenderer>
            <mx:Component>
            <mx:CheckBox selected="{data.Test}" label="{data.dir}"/>
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
            </mx:columns>
            </mx:DataGrid>

            <!-- BUG??? Why doesn't this work with an XML data provider? -->
            <!-- What are my options for getting it to work with the XML data provider? -->
            <!-- I'd prefer a solution that is similar to the current code "framework" I've got. -->
            <mx:DataGrid dataProvider="{myTestXML}" width="200" height="100" editable="true">
            <mx:columns>
            <mx:DataGridColumn headerText="myTestXML" dataField="Test" rendererIsEditor="true" editorDataField="selected">
            <mx:itemRenderer>
            <mx:Component>
            <mx:CheckBox selected="{data.Test}" label="{data.dir}"/>
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
            </mx:columns>
            </mx:DataGrid>

            <!-- BUG??? Why doesn't this work with an XML data provider with Attributes? -->
            <!-- What are my options for getting it to work with the XML data provider? -->
            <!-- I'd prefer a solution that is similar to the current code "framework" I've got. -->
            <mx:DataGrid dataProvider="{myTestXMLAttributes}" width="200" height="100" editable="true">
            <mx:columns>
            <mx:DataGridColumn headerText="myTestXMLAttributes" dataField="@Test" rendererIsEditor="true" editorDataField="selected">
            <mx:itemRenderer>
            <mx:Component>
            <mx:CheckBox selected="{data.Test}" label="{data.dir}"/>
            </mx:Component>
            </mx:itemRenderer>
            </mx:DataGridColumn>
            </mx:columns>
            </mx:DataGrid>

            </mx:Application>

            Cheers,
            Jeff
            • 4. Re: Stumped: Inline renderer for DataGridColumn with XML dataprovider
              peterent Level 2
              Set your dataProvider="{myTestXMLAttributes.partition}" as that is an XMLList and what you are providing is not a list, even though it looks like you are doing it, you are actually supply the DataGrid with a single node. Adding .partion selects all of the nodes whose name is partition and that result is an XMLList.
              • 5. Re: Stumped: Inline renderer for DataGridColumn with XML dataprovider
                Opsware_Jeff Level 1
                Thanks peterent, I had tried that early on in my experiments, but I ruled it out because it generates a red "x" error on the line when I try to save. The error is "1119: Access of possibly undefined property partition through a reference with static type mx.collections:XMLListCollection."

                Any other ideas?

                Thanks,
                Jeff
                • 6. Re: Stumped: Inline renderer for DataGridColumn with XML dataprovider
                  ntsiii Level 3
                  In the second DG, try this:
                  <mx:CheckBox selected="{data.Test==true}" label="{data.dir}"/>

                  Let me know if it works for that one.

                  Tracy
                  • 7. Re: Stumped: Inline renderer for DataGridColumn with XML dataprovider
                    ntsiii Level 3
                    This is weird. This worked for me, see if it works for your
                    * <mx:CheckBox selected="{data.@Test == true}" label="{data.@dir}"/>
                    Because the data is in the attributes. The explicit == true is necessary or it won't work. Don't ask me why, probably a datatype issue

                    * I wrapped the checkbox in a VBox. Otherwise I get an error

                    below is my code, I changed the attribute Test to selected, but that should not make any differenct.

                    Tracy

                    <mx:DataGridColumn headerText="myTestXMLAttributes" rendererIsEditor="true" dataField="@selected" editorDataField="selected">
                    <mx:itemRenderer>
                    <mx:Component>
                    <mx:VBox>
                    <mx:CheckBox selected="{data.@selected == true}" label="{data.@dir}" />
                    </mx:VBox>
                    </mx:Component>
                    </mx:itemRenderer>
                    </mx:DataGridColumn>
                    • 8. Stumped: Inline renderer for DataGridColumn with XML dataprovider
                      Opsware_Jeff Level 1
                      Thank you Tracy, we are almost there!

                      Your suggestion for the explicit boolean comparison works for the non-Attribute XML case (the second dataGrid in my example code). For the XML with Attributes case (my third example), wrapping it in a VBox for no apparrent reason does allow the dataGrid to be rendered. However, it renders only one backslash "C:\", not two "C:\\". Worst of all, after you click one of the check boxes on and off as you like, clicking the other check box will cause a runtime error!

                      Cheers,
                      Jeff

                      P.S. Below is my current example code:


                      <?xml version="1.0"?>
                      <mx:Application xmlns:mx=" http://www.adobe.com/2006/mxml" height="400" width="250">

                      <mx:ArrayCollection id="myTestArray">
                      <mx:Object dir="C:\\" Test="true"/>
                      <mx:Object dir="D:\\" Test="false"/>
                      </mx:ArrayCollection>

                      <mx:XMLListCollection id="myTestXML">
                      <mx:XMLList xmlns="">
                      <partition>
                      <dir>C:\\</dir>
                      <Test>true</Test>
                      </partition>
                      <partition>
                      <dir>D:\\</dir>
                      <Test>false</Test>
                      </partition>
                      </mx:XMLList>
                      </mx:XMLListCollection>

                      <mx:XMLListCollection id="myTestXMLAttributes">
                      <mx:XMLList xmlns="">
                      <partition dir="C:\\" Test="true"/>
                      <partition dir="D:\\" Test="false"/>
                      </mx:XMLList>
                      </mx:XMLListCollection>

                      <!-- This works just fine with an Array data provider... nice, clean, simple! -->
                      <mx:DataGrid dataProvider="{myTestArray}" width="200" height="100" editable="true">
                      <mx:columns>
                      <mx:DataGridColumn headerText="myTestArray" dataField="Test" rendererIsEditor="true" editorDataField="selected">
                      <mx:itemRenderer>
                      <mx:Component>
                      <mx:CheckBox selected="{data.Test}" label="{data.dir}"/>
                      </mx:Component>
                      </mx:itemRenderer>
                      </mx:DataGridColumn>
                      </mx:columns>
                      </mx:DataGrid>

                      <!-- Working for an XML data provider, but not obvious why it needs to be this way. -->
                      <mx:DataGrid dataProvider="{myTestXML}" width="200" height="100" editable="true">
                      <mx:columns>
                      <mx:DataGridColumn headerText="myTestXML" dataField="Test" rendererIsEditor="true" editorDataField="selected">
                      <mx:itemRenderer>
                      <mx:Component>
                      <mx:CheckBox selected="{data.Test==true}" label="{data.dir}"/>
                      <!-- Below is what I wanted to do, that is, use the boolean data
                      directly just like the "myTestArray" example. It didn't work,
                      though, so I had to check indirectly. -->
                      <!--<mx:CheckBox selected="{data.Test}" label="{data.dir}"/> -->
                      </mx:Component>
                      </mx:itemRenderer>
                      </mx:DataGridColumn>
                      </mx:columns>
                      </mx:DataGrid>

                      <!-- Still not working!!! In addition to it's needing to be wrapped in a VBox for no
                      apparent reason, when it does render, it renders only one backslash "C:\", not two "C:\\".
                      Worst of all, after you click one of the check boxes on and off as you like, clicking the
                      other check box will cause a runtime error. -->
                      <mx:DataGrid dataProvider="{myTestXMLAttributes}" width="200" height="100" editable="true">
                      <mx:columns>
                      <mx:DataGridColumn headerText="myTestXMLAttributes" dataField="@Test" rendererIsEditor="true" editorDataField="selected">
                      <mx:itemRenderer>
                      <mx:Component>
                      <!-- Not obvious why this needs to be wrapped in a VBox to work, but
                      it does, or otherwise it dies with a runtime error before even
                      rendering. Again, I don't see why it can't be as simple as the
                      "myTestArray" example. -->
                      <mx:VBox>
                      <mx:CheckBox selected="{data.@Test==true}" label="{data.@dir}"/>
                      </mx:VBox>
                      </mx:Component>
                      </mx:itemRenderer>
                      </mx:DataGridColumn>
                      </mx:columns>
                      </mx:DataGrid>

                      </mx:Application>