Select to view content in your preferred language

Putting a hyperlink into a datagrid

872
2
Jump to solution
11-30-2010 10:23 AM
KenBuja
MVP Esteemed Contributor
In an application I've developed, I'm using the TOC control to let the user show the different layers of some different services. In addition to that, the user can click on the map to get an InfoWindow that contains the attributes of all the visible layers at that point. This InfoWindow contains tabs for each of the returned layers, with a datagrid of the features and their attributes. When the user rolls the mouse over the rows in the datagrid, I've added listeners to highlight the feature. Since these datagrids will vary with the different attributes, I'm building them each dynamically. That part works fine, but now my colleagues are asking for additional functionality.

Some of the layers (but not all, of course) will have a field containing a URL and we want the user to be able to use that as a hyperlink. I've tried identifying the field that will usually contain the URL and set the ItemRenderer for that DataGridColumn using a component that was created by coder extraordinaire Robert Scheitlin but I'm getting the error "1067: Implicit coercion of a value of type Class to an unrelated type mx.core:IFactory"

What am I doing wrong on this? And is there a way of finding the field that contains a URL (possibly by searching for the string "http:" in the result) without hard coding a field name (here, it's "Source")?

Hers the result function from the IdentifyTask that I'm using to build the datagrids, tabs, and InfoWindow:

                function resultFunction(results:Array, clickGraphic:Graphic):void
                {
                    var myInfoRenderer:InfoRenderer = new InfoRenderer;
                    var mapPoint:MapPoint = MapPoint(clickGraphic.geometry);
                    var point:Point = map.toScreen(mapPoint);
                    
                    if (results && results.length > 0)
                    {
                        var oldLayer:Number = -1;
                        var resultsArray:Array = [];
                        var result:IdentifyResult;
                        var resultGraphic:Graphic;
                        var tab:TabNavigator = new TabNavigator();
                        var newVBox:VBox = new VBox;
                        var newText:Text = new Text;
                        var newDG:DataGrid = new DataGrid;
                        var graphic:Graphic;
                        
                        clickGraphicsLayer.add(clickGraphic);                
                
                        result = results[0];
                        resultsArray.push(result.feature.attributes);
                        newText = new Text;
                        newText.text = result.layerName;
                        graphic = result.feature;
                        graphic.alpha = 0.3;
                        graphicsLayer.add(graphic);
                        tab.width = 400;
                        tab.height = 230;
                        
                        for (var i:int = 1; i < results.length; i++)
                        {

                            result = results;
                            graphic = new Graphic;
                            graphic = result.feature;
                            graphic.alpha = 0.3;
                            graphicsLayer.add(graphic);                            
                            if (result.layerId == oldLayer)
                            {
                                resultsArray.push(result.feature.attributes);
                            }
                            else
                            {
                                newDG = new DataGrid;
                                newVBox = new VBox;
                                newDG.dataProvider = resultsArray;
                                
                                //this is the new code section
                                if (!(result.feature.attributes.Source == undefined))
                                {
                                    for each (var dgCol:DataGridColumn in newDG.columns)
                                    {
                                        if (dgCol.dataField == "Source")
                                        {
                                            dgCol.itemRenderer = HyperLinkField; //coercion error here
                                        }
                                    }
                                }
                                //end of new code section

                                newDG.addEventListener(ListEvent.ITEM_CLICK, newDG_ItemRollOver, false, 0, true);
                                newDG.addEventListener(ListEvent.ITEM_ROLL_OUT, newDG_ItemRollOut, false, 0, true);
                                newDG.addEventListener(ListEvent.ITEM_ROLL_OVER, newDG_ItemRollOver, false, 0, true);
                                newVBox.addChild(newText);
                                newVBox.addChild(newDG);
                                tab.addChild(newVBox);
                                myInfoRenderer.addChild(tab);
                                
                                newText = new Text;
                                newText.text = result.layerName;
                                resultsArray = [];
                                resultsArray.push(result.feature.attributes);
                            }
                            oldLayer = result.layerId
                        }
                        newVBox = new VBox;
                        newDG = new DataGrid;
                        newDG.addEventListener(ListEvent.ITEM_CLICK, newDG_ItemRollOver, false, 0, true);
                        newDG.addEventListener(ListEvent.ITEM_ROLL_OUT, newDG_ItemRollOut, false, 0, true);
                        newDG.addEventListener(ListEvent.ITEM_ROLL_OVER, newDG_ItemRollOver, false, 0, true);
                        newVBox.addChild(newText);
                        newDG.dataProvider = resultsArray;
                        
                       //this is the new code section
                       if (!(result.feature.attributes.Source == undefined))
                        {
                            for each (var dgCol:DataGridColumn in newDG.columns)
                            {
                                if (dgCol.dataField == "Source")
                                {
                                    dgCol.itemRenderer = HyperLinkField;//coercion error here
                                }
                            }
                        }
                       //end of new code section 

                       newVBox.addChild(newDG);
                        tab.addChild(newVBox);
                        myInfoRenderer.addChild(tab);
                        
                        cursorManager.removeBusyCursor();
                        
                        map.infoWindow.content = myInfoRenderer;
                        map.infoWindow.show(map.toMap(point));
                        map.infoWindow.addEventListener(Event.CLOSE,infoWindow_Close, false, 0, true);
                    }
                }
Tags (2)
0 Kudos
1 Solution

Accepted Solutions
RobertScheitlin__GISP
MVP Emeritus
Ken,

   I am not sure about seaching the attribute to see if it needs to have a hyperlinkcolumn but the coersion issue is simply this:

dgCol.itemRenderer = new ClassFactory(HyperLinkField); //coercion error here

View solution in original post

0 Kudos
2 Replies
RobertScheitlin__GISP
MVP Emeritus
Ken,

   I am not sure about seaching the attribute to see if it needs to have a hyperlinkcolumn but the coersion issue is simply this:

dgCol.itemRenderer = new ClassFactory(HyperLinkField); //coercion error here
0 Kudos
KenBuja
MVP Esteemed Contributor
Thanks, Robert. That did it.
0 Kudos