2 Replies Latest reply on Oct 16, 2008 12:17 PM by ntsiii

    AdvancedDataGrid as a itemRenderer

    brad_rice
      I am trying to make a list menu using advanceddatagrid. What I would like is a 1 column item with a tree control. I have created that. Then when you pull it down it pulls in a data grid below it.

      I have this mxml code:

      <mx:Canvas width="300" height="800" id="outerCanvas" >

      <mx:AdvancedDataGrid rowCount="0" width="100%" height="100%" id="location_list" variableRowHeight="true" dataProvider="{argumentData}" change="handleClick(event);"
      folderClosedIcon="{null}"
      folderOpenIcon="{null}"
      defaultLeafIcon="{null}" >
      <mx:columns>
      <mx:AdvancedDataGridColumn headerText="" width="20"/>
      <mx:AdvancedDataGridColumn dataField="@label" headerText=""/>

      <!--<mx:AdvancedDataGridColumn dataField="key" headerText="Key" width="30"/>
      <mx:AdvancedDataGridColumn dataField="name" id="b_name" headerText="Building Name"/>-->
      </mx:columns>


      <mx:rendererProviders>
      <mx:AdvancedDataGridRendererProvider
      depth="2"
      columnIndex="0"
      columnSpan="0"
      rowSpan="0"
      renderer="buildingLoc"/>
      </mx:rendererProviders>



      </mx:AdvancedDataGrid>


      </mx:Canvas>
      </mx:Application>

      and this is my renderer

      <mx:DataGrid xmlns="*" xmlns:mx=" http://www.adobe.com/2006/mxml" showHeaders="false">
      <mx:Script>
      <![CDATA[
      override public function set data(value:Object):void
      {
      dataProvider = value;
      }
      ]]>
      </mx:Script>

      <mx:columns>
      <mx:DataGridColumn dataField="key" headerText="Key" />
      <mx:DataGridColumn dataField="name" headerText="Building Name" />
      </mx:columns>

      </mx:DataGrid>

      what seems to happen is it creates a separate datagrid for each element of the data set. How do I nest the datagrid in so it just displays as a list?

      Here is my compiles swf so you can see what is going on:

      http://bradrice.com/test/testList.swf

      and my xml is here:

      http://bradrice.com/test/assets/buildingList.xml

      any help would be appreciated. I have banged my head on this one.
        • 1. Re: AdvancedDataGrid as a itemRenderer
          brad_rice Level 1
          I think I figured out how to create my menu from the advanceddatagrid using an itemRenderer. Here it is working:

          http://bradrice.com/test/testList2.swf

          I changed the renderer to this:

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

          <mx:HBox paddingLeft="2" xmlns:mx=" http://www.adobe.com/2006/mxml" >
          <mx:Script>
          <![CDATA[
          override public function set data( value:Object ) : void {
          super.data = value;
          }



          ]]>
          </mx:Script>
          <mx:Label text="{data.key}" width="30" />
          <mx:Text width="100%" text="{data.name}" />
          </mx:HBox>

          Now, one thing I would like to do is somehow remove the change event on just the top level list items. Right now if you click one of the items you will get some data from the item. However the top level items don't have the data and I don't want the event to fire when you click them. Any thoughts anybody?
          • 2. Re: AdvancedDataGrid as a itemRenderer
            ntsiii Level 3
            In the click handler, test for the top level item and call event.preventDefault()

            Haven't actually done this with a click or itemClick event but it works with the editing events.

            Tracy