:: Forum >> Version 1 >>

Editable templates with XML data model

It is possible to make editable templates (like this one - /javascript.forum.1394.8/ ) 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(valueij){
        var 
node this.getNode(ij);
        
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(valueij){
        var 
node this.getNode(ij);
        
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 /javascript.forum.1394.8/
Alex (ActiveWidgets)
Friday, July 16, 2004
When you edit the table, is there a way to saveback the XML data to the file, or to a new file?
Matt
Wednesday, September 1, 2004

I don't know if JavaScript can do this. You need to use some server side code to do this.
Sudhaker Raj
Friday, September 10, 2004
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?
Lori
Tuesday, October 19, 2004
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)
Tuesday, October 19, 2004
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
break;
// 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
Wednesday, October 20, 2004
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
Lombardi
Friday, September 16, 2005



This topic is archived.

Back to support forum

Forum search