3.2.0

Hyperlinks to a new window

I am new to Javascript and writing my first personal web page, using XML to provide the data model for the grid. One of the columns contains hyperlinks to other sites and I want the user to be able to click on the link and open that URL in a new window. I've tried adding the link template as described in some other messages, and I see the text in hyperlink form on the grid. When I click on the link, I get a new window, but it is the about:blank window and not the correct URL.

I think that I may need to set the link item property, however, I haven't had any luck trying to add lines to do this. If this is what is missing, a specific code example would be helpful.

Here's my code:

var xml = new Active.XML.Table;
xml.setURL("data/" + getSelectedName() + "_wish_lists.xml");
xml.setRows("//gift");
xml.request();

// define column labels
var columns = ["Gift description", "Priority", "Location", "Price"];

// create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;
obj.setProperty("column/count", 4);

// provide column labels
obj.setColumnProperty("texts", columns);

// provide external model as a grid data source
obj.setDataModel(xml);

// Convert the text in column 3 to hyperlinks.
var link = new Active.Templates.Link;
link.setAttribute("target", "_new");
obj.setColumnTemplate(link, 2);

// write grid html to the page
document.write(obj);
Lori
October 4,
You have to add link property to your XML data model:

xml.getLink = function(i, j){
    var valueNode = this.getNode(i, j);
    return valueNode ? valueNode.getAttribute("href") : "";
}


The above example assumes that your URL is stored in 'href' attribute of the same node as your column 2 value. Othervise you can run XPath query relative to your value node:

xml.getLink = function(i, j){
    var valueNode = this.getNode(i, j);
    var linkNode = valueNode ? valueNode.selectSingleNode("./relativeXPath") : null;
    return linkNode ? linkNode.text : "";
}


or if your URL is defined, say, as colum 5 - you can just say

xml.getLink = function(i, j){
    return this.getText(i, 5);
}

Alex (ActiveWidgets)
October 11,
Is there a way to do this with CSV text instead of XML?
shortmatt
July 6,

This topic is archived.

See also:


Back to support forum