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:

//	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

    //	start asyncronous data retrieval

    //	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

    //	provide external model as a grid data source

    //	write grid html to the page

plus My.Templates.Input class from http://www.activewidgets.com/messages/1394-8.htm
Alex (ActiveWidgets)
July 16,
When you edit the table, is there a way to saveback the XML data to the file, or to a new file?
September 1,

I don't know if JavaScript can do this. You need to use some server side code to do this.
Sudhaker Raj
September 10,
I tried adding the setText method as described above, but it is never getting called. Do I have to call it explicitly when the data changes or should it be called automatically?
October 19,
If you use editable template and call setItemProperty("text", value) there - it will result in data model setText(value, i, j) call.

template.setItemProperty("text", value) ->
grid.setDataProperty("text", value, i, j) ->
data.setText(value, i, j)
Alex (ActiveWidgets)
October 19,
I want to add onkeydown event to the My.Templates.Input
to catch tab, enter, arrow keys...

I suppose this is a good start:
editor.setEvent("onkeydown", function() {
var ieCode = event.keyCode;
switch (ieCode)
case: '9': // TAB
// Do something
// other cases....

my question is, How can I get access to the grid object to get
a: certain values from other cells in the same row
and b : switchToEditMode on the next editable field?
Koen dB
October 20,
I could'n make the data write work on Netscape 7. If I don't patch with if (window.Element) {
Element.prototype.__defineSetter__("text", function(value){
this.firstChild.nodeValue = value;

the information does not go to XML data so I it get lost, but if I add the code the grid does not show any rows and give me this error
this.getProperty("data/text", _optionscol, this.getProperty("item/index")) has no properties
September 16,

This topic is archived.

See also:

Back to support forum