Active.Format Object's access to data in other columns of the model
I was trying to write the Anchor Format object I saw alluded to on one of the other posts. I tried doing this with a Template, but it seemed that the template was only initialized once, and didn't allow for dynamic rendering of the link, but this was probably my ignorance of the codebase and very limited knowledge of javascript's runtime rules.
The following works for static links and would also allow the raw data value to be part of the hyper link but is fairly limited in what it can do. I want to make it possible for any columns data value to be part of the href attribute.
Is there a standard way to reference the model from a Format Object?
What is the property to get the models current row?
I want to be able to resolve properties in a Format Object using other columns from the model's current row however, I am not sure how to reference the other columns data values, or reference the current row
I was thinking of using a syntax such as
var myAnchorFormat = new Active.Formats.Anchor();
myAnchorFormat.setLink( "http://www.google.com?q={1}" );
Where "{1}" would be resulved to the data value from model.getData(currentRow, 1);
I could set the model into the Anchor Format Object, but then I still wouldn't know the current row. I thought I had seen this in the forum somewhere, but I've been looking for a few days, and haven't been able to find it.
Here is what I have so far.
The following works for static links and would also allow the raw data value to be part of the hyper link but is fairly limited in what it can do. I want to make it possible for any columns data value to be part of the href attribute.
Is there a standard way to reference the model from a Format Object?
What is the property to get the models current row?
I want to be able to resolve properties in a Format Object using other columns from the model's current row however, I am not sure how to reference the other columns data values, or reference the current row
I was thinking of using a syntax such as
var myAnchorFormat = new Active.Formats.Anchor();
myAnchorFormat.setLink( "http://www.google.com?q={1}" );
Where "{1}" would be resulved to the data value from model.getData(currentRow, 1);
I could set the model into the Anchor Format Object, but then I still wouldn't know the current row. I thought I had seen this in the forum somewhere, but I've been looking for a few days, and haven't been able to find it.
Here is what I have so far.
Active.Formats.Anchor = Active.Formats.String.subclass();
Active.Formats.Anchor.create = function(){
var obj = this.prototype;
var _link = null;
obj.setLink = function( l ) {
_link = l;
}
obj.getLink = function(src,data) {
var l = _link;
if (typeof(l)=="function") {
l = l.call(this,src,data);
}
return l;
}
obj.dataToText = function(data){
var html = new Active.System.HTML();
html.setTag("a");
html.setContent(data);
if (_link) {
html.setAttribute( "href", obj.getLink(this,data) );
}
return html;
};
obj.dataToValue = function( data ) {
return data;
}
// plus some regex code to extract and replace
// column references with their values from the result of
// _link
};
Active.Formats.Anchor.create();
gbegley
March 29,