views:

1047

answers:

2

Hi community,

I wanted to ask how I can put links into a datagrid. My dataProvider is the folling xml

<xml>
 <item>
  <name>A name</name>
  <url>A url</name>
 </item>
 <item>
  <name>Another name</name>
  <url>Another url</name>
 </item>
</xml>

sure with some more items in it. Now I want to have a datagrid that displays the name as a label and when clicking on the row the url is opened.

Can anyone help me with that thing? I know some stuff about item renderes but I don't know how I can give the url to the item renderer. Maybe with a classfactory? But how can I control which url is given to the specific item renderer?

Thanks in advance

Sebastian

+1  A: 

Can you just do what you want using the click event handlers?

<mx:Script>
 <![CDATA[
  import flash.net.navigateToURL;


  protected function datagrid1_clickHandler(event:MouseEvent):void
  {
   if(dg1.selectedItem)
   {
    var request:URLRequest = new URLRequest(dg1.selectedItem.url);
    navigateToURL(request);
   }
  }

  [Bindable]
  public var xml:XML = new XML(<xml>
  <item>
   <name>A name</name>
   <url>http://www.google.com&lt;/url&gt;
  </item>
  <item>
   <name>Another name</name>
   <url>http://www.yahoo.com&lt;/url&gt;
  </item>
 </xml>);
 ]]>
</mx:Script>
<mx:DataGrid id="dg1" editable="true" click="datagrid1_clickHandler(event)" dataProvider="{xml.children()}">
 <mx:columns>
  <mx:DataGridColumn dataField="name" />
 </mx:columns>
</mx:DataGrid>
ryanstewart
A: 

Muchas gracias, encontré este sitio por casualidad, y me ha servido de mucho! muy fácil, y claro!

Guillermo - Argentina

Guillermo