:: Forum >>

Loading Table from XML in JavaScript variable

For several reasons I have to do SOAP using some non-AW JavaScript. This works fine, I end up with a J/S object that is a collection of XML nodes which I can either use myVar.xml or myVar.text to get the values I expected. However, I cannot seem to get that in an AW.XML.Table or view correctly in my AW grid.

I have an XMLHTTP request that returns my response, which gets
further parsed down the the correct part of the XML with:

var nd = responseNode.getElementsByTagName("Checks")[0];

I thought it would be as simple as setting the table's XML like:

var table = new AW.XML.Table;
var obj = new AW.UI.Grid;
var columns = ["Check No", "Amount", "Date"];

var str = new AW.Formats.String;
var num = new AW.Formats.Number;
var money = new AW.Formats.Number;
money.setTextFormat("$ #,###,###.##");
var dte = new AW.Formats.Date;

obj.setCellFormat([str, money, dte]);



But this doesn't work at all.

My XML looks like:

<Checks> <CheckRow><CheckNo>1</CheckNo><Amount>123.45</Amount><CheckDate>2000-01-01</CheckDate></CheckRow>

I've tried various iterations of the setXML:



All of which do not work, and I believe the nd.text part even gives me an
error saying that's the wrong object type passed.

I've also tried to display the nd.xml before I create the table & grid,
and it's perfect. I can't even do var myVar = table.getXML(); after
the setXML - that returns nothing.

To complicate this - if I store my XML to a file, the exact way
it's stored in nd.xml, I can then setURL("myXML.xml") and request() -
and the grid displays perfectly!

It's like setXML() is just broken. Or there's some other step
the request() does behind the scenes that's missing for
the table to be initialized and useable for the
setCellModel(). (but I'm thinking it's the table and not
just the grid since I can't seem to get the getXML()
to return the right values either.

Any suggestions?

Tuesday, March 6, 2007
OK, so I'll answer my own question then, having pretty much stumbled across the answer:

"Or there's some other step
the request() does behind the scenes that's missing for
the table to be initialized and useable for the

That statement ends up being true!! I didn't go so far as searching through the code to find it, but I found an example in the forum based on the docs that used setXML(). It didn't work at first untill I just totally stripped down everything to *just* the code in the example and it worked!!

At first I thought something in setting my grid options was at fault and stripped those out of my test code. Still didn't work. Then I noticed only one single difference in my test code and the working sample provided in the forum - a setRowCount()!!

It appears the request() done on the table also sets up the number of rows in the table! So after putting in a quick setRowCount() grabbing the correct number from my XML object nd.childNodes.length and all is perfect!

Just a suggest to Alex - if request() in fact does run a few quick things after the loading of the XML, consider putting the same quick things into the setXML() so it's consistent no matter where the XML comes from.

Thanks for listening.
Wednesday, March 7, 2007
Geoff, I agree. The current code in response() method should not be there, it should be some kind of event handler on the grid itself.
Alex (ActiveWidgets)
Thursday, March 8, 2007
Like I said, I didn't entirely search through the code, but I can say that at least part of the code in request() should be in the table code, not somewhere else. If the number of rows and the like are attached to the table, then that's where they should go. Then the grid has what it needs when the setCellModel() is done. The biggest issue I see is that request() and setXML() are set apart correctly. I would think request() should call setXML() - and the things that happen that are table specific should be there. If that includes something like setting number of rows, then either request() calls setXML() and it sets the rows as well as the XML string, or you have a third function which request and setXML() both call. I could see the grid code being in setCellModel() but only if all the code in all places is removed out of the table. And I suspect that's more code than should be moved around - I think it belongs there.
Tuesday, March 13, 2007

This topic is archived.

Back to support forum

Forum search