Select to view content in your preferred language

Problem with Hyperlinks

2123
1
07-20-2010 08:34 AM
Joshuacalhoun
New Contributor
Hi everyone,

I am trying to get a Data Grid  to pop up (or it could remain static) when a user clicks or mouses over a line feature. I think this part is manageable. However, I want in the data grid, a field for hyperlinks that the user can click to view a .pdf file.

The problem is that my hyperlink field values do not contain the full paths. On the current .net site, we have the first half written in code and this is concatenated with the last half that remained in the field.

Is there a way to do this in Flex?

any help or advice you all can give me will be greatly appreciated.

Thanks,

Josh Calhoun
Chattanooga GIS
Tags (2)
0 Kudos
1 Reply
ReneRubalcava
Frequent Contributor II
If you want a clickable link, you'll want to set up the labelFunction of the DataGrid, which would look something like this

protected function formatURL(item:Object, column:DataGridColumn):String {
column.itemRenderer = null;
if (column.dataField == "URLData" ) {
 column.itemRenderer = new ClassFactory(UrlLinkButton);
 return item.URLData;
}
else if (column.dataField == "Name") // set up checks for other field names
 return item.Name;
else
 return "ERR: No Field name defined";
}


With an ItemRenderer for your field that could look like this.
<?xml version="1.0" encoding="utf-8"?>
<mx:LinkButton xmlns:fx="http://ns.adobe.com/mxml/2009"
      xmlns:s="library://ns.adobe.com/flex/spark"
      xmlns:mx="library://ns.adobe.com/flex/mx"
      fontWeight="bold"
      color="#0000FF"
      label="{data.URLData}"
      click="openURL()">
 <fx:Script>
  <![CDATA[
   /**
    * Function that will parse current date and given URL info into a url string to be opened in a new page.
    **/
   protected function openURL():void {
    trace("button clicked, attempt to parse to URL");
    if (data.URLData) {
     // concatenate url string
     var url:String = "url information" + data.URLData + "maybe more url information";
     trace("send drawing url request");
     navigateToURL(new URLRequest(url));
    }
   }
  ]]>
 </fx:Script>
 <fx:Declarations>
  <!-- Place non-visual elements (e.g., services, value objects) here -->
 </fx:Declarations>
</mx:LinkButton>


This way, the URL opens only if they click in that field.
Of course you could bypass the ItemRenderer and use the openURL() on an ItemClickEvent if you don't mind that the URL will open when they click the row in the DataGrid.
0 Kudos