:: Forum >>

setHeaderText from AW.XML.Table column names

I have the following example code

var table = new AW.XML.Table;
table.setParameter("name", "value");
table.setRows("//NewDataSet/*"); // data rows XPath

var grid = new AW.UI.Grid;
grid.setHeaderText(["ID", "Author", "Year Born"]);

But since the table load from the database already has the column names I would like not to hardcode the names, just get them from the aw.table.xml column names.
Is this posiible. Please help.
Thursday, September 27, 2007
It looks that my question does not make sense.

table.request(); -- doesn't call the webservice and loads the data from the table. The load is done later when the grid is refreshed or writen.

I guess that's why in the Forum for version 1 there is this note:

Dynamically setting Column Text (Headers) From XML Document

I figured out how to assign column headings from the XML Table Model using xpath. Simply override the model.response() function like this.

var grid = ...; // setup grid
var model = ...; // setup model (Using XML Table of course)
var columnTextXpath = "//headers/header"; // or your own friendly xpath
var model_response = model.response;
model.response = function( xml ) {
var hNodes = xml.selectNodes( columnTextXpath );
if (hNodes) {
var h = new Array();
for( i=0; i<hNodes.length; i++ ) {
h.push( hNodes[i].text );
grid.setColumnTexts( h );
model_response.call( model, xml );

The url for this note is:
Thursday, September 27, 2007
Here is the example for AW 2.0 - it is supposed to work with MS dataset serialized to XML (as in /examples/grid data - xml/dataset.xml) -

var table = new AW.XML.Table;
table.setNamespace("xs", "http://www.w3.org/2001/XMLSchema");

table.response = function(data){


    var grid = this.$owner;
    var xml = this._xml;
    var xpath = "//xs:sequence/xs:element";
    var nodes = AW.ie ? xml.selectNodes(xpath) : xml.evaluate(xpath, xml, this._ns, 7, null);
    var columnCount = AW.ie ? nodes.length : nodes.snapshotLength;
    var i, headerText = [];
    for(i=0; i<columnCount;i++){
        headerText.push((AW.ie ? nodes[i] : nodes.snapshotItem(i)).getAttribute("name"));




The code selects 'schema' nodes with //xs:sequence/xs:element XPath and copies column names into headerText array.
Alex (ActiveWidgets)
Monday, October 1, 2007

This topic is archived.

Back to support forum

Forum search