data Island help Alex
Hey,
I am learning a lot playing with this xml adPersistXML
data islands. I am having one major prolbem though.
When the recordset returns a null value, the xml attribute is not created, and the AW Grid will bump the next columns data over to the wrong column.
Any way for active widgets to know when an attribute is null, and just put in an empty string?
I realize I can do stuff at the query level to fix this, but We are planning on using the grid on a lot of pages, and my boss does not want us to have to reformat all the queries.
Jim Shaffer
October 26,
Jim,
if your data has irregular structure you can specify XPath expression for each column
table.setColumns(["ticker", "name", "mktcap", "sales", "employees"]);
Complete example:
<html>
<head>
<title>ActiveWidgets Grid :: Examples</title>
<link href="../../runtime/styles/xp/aw.css" rel="stylesheet" type="text/css" ></link>
<script src="../../runtime/lib/aw.js"></script>
<style>
.aw-grid-control {height: 150px; width: 100%; font: menu;}
</style>
</head>
<body>
<xml id="xmlDataIsland">
<companies>
<company>
<ticker>MSFT</ticker>
<name>Microsoft Corporation</name>
<mktcap>314,571.156</mktcap>
<sales>32,187.000</sales>
<employees>55000</employees>
</company>
<company>
<name>Oracle Corporation</name>
<mktcap>62,615.266</mktcap>
<sales>9,519.000</sales>
<employees>40650</employees>
</company>
<company>
<ticker>SAP</ticker>
<sales>8,296.420</sales>
</company>
</companies>
</xml>
<script>
var table = new AW.XML.Table;
var xml = document.getElementById("xmlDataIsland");
table.setColumns(["ticker", "name", "mktcap", "sales", "employees"]);
table.setXML(xml);
var columns = ["Ticker", "Company Name", "Market Cap.", "$ Sales", "Employees"];
var obj = new AW.UI.Grid;
obj.setColumnCount(5);
obj.setRowCount(3);
obj.setHeaderText(columns);
obj.setCellModel(table);
document.write(obj);
</script>
</body>
</html>
Alex (ActiveWidgets)
October 26,
With XPath you can display node attributes or even complex search results :-)
Attributes example:
<xml id="xmlDataIsland">
<companies>
<company ticker="MSFT" name="Microsoft Corporation">
<mktcap>314,571.156</mktcap>
<sales>32,187.000</sales>
<employees>55000</employees>
</company>
<company ticker="ORCL" name="Oracle Corporation">
<mktcap>62,615.266</mktcap>
<sales>9,519.000</sales>
<employees>40650</employees>
</company>
<company ticker="SAP" name="SAP">
<sales>8,296.420</sales>
</company>
</companies>
</xml>
The XML above can be linked with the following set of XPaths:
table.setColumns(["@ticker", "@name", "mktcap", "sales", "employees"]);
Alex (ActiveWidgets)
October 26,
Awesome, thanks My Brother.
Jim Shaffer
October 26,
And how can I separate "/companies/company/sales" and "/companies/salesman/sales" ?
Should I specify full xpath for table.setColumns([....]); ?
Andrew V.
June 28,
Use setRows() to specify XPath for the row nodes -
table.setRows("company");
or
table.setRows("//company");
The column XPath is executed relative to the row node, so it would still be
table.setColumns(["sales", ...]);
Alex (ActiveWidgets)
June 28,
I am facing issue with
row count. The xml is retrieved as a String object from a JSP. When i use
data <- from JSP
var obj = new AW.UI.Grid;
obj.setHeaderText(myHeaders);
var table = new AW.XML.Table;
table.setXML(data);
obj.setCellModel(table);
obj.setColumnCount(4);
If i dont specify the row count, the data will not be displayed in the grid. Is there a way that i can set the row count. I've tried
obj.getRowCount(); with no luck.
Raj Nair
June 28,