3.0.0

Populating multiple grids from the same XML message?

I may have posted a similar question before, but can't find it, or any unrelated posts which answer it.

I wish to receive a single XML message and display the data in two separate grids. I had wondered if a many-to-one Grid-Table was relationship possible. However, the fact that setRows is a method of AW.XML.Table suggests that a single Table instance can't solve this problem. If Grids set their own internal 'rows' property when the setCellModel is called then some trickery might make it possible? How does it work Alex?

Another alternative I considered is doing something like:

var table1 = new AW.XML.Table();
table1.setRows("//xpath/appropriate/for/grid1");
table1.response = function(xml) {
...
var rootNodeForTable2 = this.getXML().getElementById("idOfRelevantNode");
table2.setXML(rootNodeForTable2 );
...
}
var grid1 = new AW.UI.Grid();
grid1.setCellModel(table1);

var table2 = new AW.XML.Table();
table2.setRows("//xpath/appropriate/for/grid2");
var grid2 = new AW.UI.Grid();
grid2.setCellModel(table1);

I haven't tried this yet and will give it a shot, but perhaps someone else has some other ideas?

Cheers,
Callum.
Cal
July 6,
I'll answer my own question...

As it turns out, the solution is all very intuitive. In summary, create one AW.HTTP.Request object to manage the communication. Create two separate AW.XML.Tables with associated AW.UI.Grids. Use the setRows() method of the Tables to define the correct path to the row data in the XML message. Override the HttpRequest response to call the response of each of the Tables, passing the xml as an argument. So simple! Here's some sample code which would appear within the constructor of a class:

this.httpRequest = new AW.HTTP.Request();
this.httpRequest.$owner = this;
this.httpRequest.setURL("url/for/single/xml/message/populating/both/tables");
this.httpRequest.response = function(xml) {
this.$owner.table1.response(xml);
this.$owner.table2.response(xml);
}

this.table1 = new AW.XML.Table();
this.table1.setRows("//row/xpath/for/table1/*");
this.table1.setColumns([arrayOfTable1ColumnXpaths]);

this.grid1 = new AW.UI.Grid());
this.grid1.setCellModel(this.table1);

this.table2 = new AW.XML.Table();
this.table2.setRows("//row/xpath/for/table2/*");
this.table2.setColumns([arrayOfTable2ColumnXpaths]);

this.grid2 = new AW.UI.Grid());
this.grid2.setCellModel(this.table2);

Cheers,
Callum.
Cal
July 7,

This topic is archived.

See also:


Back to support forum

Search

Version 2

Looking for AW 2.6 ?
The old site is here.