:: Forum >> Version 2 >>

setHeaderText from AW.XML.Table column names

I have the following example code

var table = new AW.XML.Table;
table.setURL("webservice.asmx/getDataSet");
table.setParameter("name", "value");
table.setRequestMethod("POST");
table.setRows("//NewDataSet/*"); // data rows XPath
table.request();

var grid = new AW.UI.Grid;
grid.setId("grid");
grid.setHeaderText(["ID", "Author", "Year Born"]);
grid.setColumnCount(3);
grid.setCellModel(table);
grid.refresh();

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.
Javier
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 );
}
model.request();


The url for this note is:
/javascript.forum.1055.9/dynamically-setting-column-text-headers.htm
Javier
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.setURL("dataset.xml");
table.setRows("//NewDataSet/*");
table.setNamespace("xs""http://www.w3.org/2001/XMLSchema");

table.response = function(data){

    
this.setXML(data);

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

    
grid.clearHeaderModel();
    
grid.clearColumnModel();
    
grid.setHeaderText(headerText);
    
grid.setColumnCount(columnCount);

    
grid.clearScrollModel();
    
grid.clearSelectedModel();
    
grid.clearSortModel();
    
grid.clearRowModel();
    
grid.setRowCount(this.getCount());
    
grid.refresh();
};

table.request();

 
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