3.2.0

Use Xml Datamodel and refer to cells via row, fieldname

I'm trying to see if I can use the ActiveWidgets model to populate a form using xml when someone clicks on a grid row (i'd create a new xml table). I was just looking at the xml data object and see that data retrieval seems to be governed via cell locations - ie: retrieve data from location 0,1. I don't see any methods that would allow one to access rows via fieldnames as well - ie: row 0, field myfield. My thinking is that the xml would return fieldnames that correspond to the ID of the field on the form that needs to be populated.

Is there something already in there that would allow access via fieldname with the XML model or is this something that I would need to hack myself? And being quite lazy, has anyone done this before ;)
Alex
December 6,
OK, that was simple enough.

obj.getDataByColumnName = function(i, columnname){

if (!this._items) {return null}
var node = null;
node = this._items[i].selectSingleNode(columnname);
return node ? node.text : null;
};

The next thing I have to figure out is how to let a control know that the table has completed retrieving data.
Alex
December 6,
OK, that was also pretty simple. Have I said how AWESOME this framework is. Good work! I was using XML for Script to do alot of my XML parsing but this is much easier and simpler AND it comes with a wonderful grid to boot ;) Probably stick to XML for Script (and it can probably be integrated into the datamodel as well) for more complex needs, but for screen "painting", your model is wonderful.

For anyone wanting to do something similar, here is the generic code. I have wrapped it in a function that gets called on a row double click. I then go through the row retrieved and then match up the column names with the fieldids and then dynamically populate the fields in the form with the data returned. Dang! Donation coming shortly ;)

function retrievedata(url) {

    var datatable = new Active.XML.Table;

    //	provide data URL
    datatable.setURL(url);

    //	set rows XPath
    datatable.setRows("//alldata/*");

    //	start asyncronous data retrieval
    datatable.request();

    var _response = datatable.response; 
    
    datatable.response = function(xml) 
    	   { 
        	      _response.call(this, xml); 
                    // do whatever you need to do with the data here.
       	   }

    datatable.request();
}
Alex
December 6,
I have tried something like that to get all the line result in a Javascript Array :
[i]
--------------------------------------------------------------------
function retrievedata(url, row) {
    var datatable = new Active.XML.Table;
    var rowValues;
    //    provide data URL
    datatable.setURL(url);
    //    set rows XPath
    datatable.setRows("//alldata/*");
    //    start asyncronous data retrieval
    datatable.request();
    var _response = datatable.response;

datatable.response = function(xml)
           {
                  _response.call(this, xml);
                    // do whatever you need to do with the data here.
                   rowValues = new Array(datatable.getValue(row, 0), datatable.getValue(row, 1), datatable.getValue(row, 2), 		datatable.getValue(row, 3), datatable.getValue(row, 4), datatable.getValue(row, 5), datatable.getValue(row, 6), datatable.getValue(row, 7), datatable.getValue(row, 8));
              }
datatable.request(); 
return rowValues;
}

var rowVal = retrievedata("test.xml", 0);
alert(rowVal);
--------------------------------------------------------------------


But the "alert" returns only : 0,0,0,0,0,0....
If I use getNode(row, i), I have no result at all : ,,,,...
How can I do to have all the results of a row in a javascript array ?
Marc Jaeger
March 10,

This topic is archived.

See also:


Back to support forum