Editable templates with XML data model
It is possible to make editable templates (like this one - http://www.activewidgets.com/messages/1394-8.htm ) working with XML data model as well. You just have to implement setText() method on the model:
The code above is IE-specific, so we have to patch Mozilla to make it work there:
Complete code based on 'xml-simple.htm' example would look like this:
plus My.Templates.Input class from http://www.activewidgets.com/messages/1394-8.htm
// modify model to write data back to the XML
table.setText = function(value, i, j){
var node = this.getNode(i, j);
node.text = value;
}
The code above is IE-specific, so we have to patch Mozilla to make it work there:
if (window.Element) {
Element.prototype.__defineSetter__("text", function(value){
this.firstChild.nodeValue = value;
});
}
Complete code based on 'xml-simple.htm' example would look like this:
// create editable text template
var template = new My.Templates.Input;
// create ActiveWidgets data model - XML-based table
var table = new Active.XML.Table;
// modify model to write data back to the XML
table.setText = function(value, i, j){
var node = this.getNode(i, j);
node.text = value;
}
// provide data URL
table.setURL("../data/companies-simple.xml");
// start asyncronous data retrieval
table.request();
// define column labels
var columns = ["Ticker", "Company Name", "Market Cap.", "$ Sales", "Employees"];
// create ActiveWidgets Grid javascript object
var obj = new Active.Controls.Grid;
// provide column labels
obj.setColumnProperty("texts", columns);
// assign new template to all columns
obj.setColumnTemplate(template);
// provide external model as a grid data source
obj.setDataModel(table);
// write grid html to the page
document.write(obj);
plus My.Templates.Input class from http://www.activewidgets.com/messages/1394-8.htm
Alex (ActiveWidgets)
July 16,