More information on this topic is available in the documentation section: /grid.howto.data/xml.html.
grid.defineCellProperty("color");
2. link the cell style (or CSS class) to the new 'color' propertygrid.getCellTemplate().setStyle("background", function(){
return this.getCellProperty("color");
});
3. now it is necessary to put some data into the 'color' property. There are two ways to do it depending on how the color information is transmitted in the XML file - i.e. whether each data element has the 'color' attribute or the 'color' is just another data column (which can also be an attribute of some element).table.getColor = function(col, row){
return this.getNode(col, row).getAttribute('color');
};
3b. if 'color' is just another data column - it should be selected in the XML source using XPath the same way as other columns -table.setColumns(['col1', 'col2', ..., 'col1/@color']);
and linked to the cell color property -grid.setCellColor(function(col, row){
return this.getCellData(colorColumnIndex, row);
});
table.setColumns(["Country", "Calls", "ASR", "PDD", "ALOC", "@bc", "@fc", "@ft"]);
and map them to the row style attributes -obj.defineRowProperty("background", function(r){
return this.getCellText(5, r); // return 'background' column
});
andmyRow.setStyle("background", function(){
return this.getRowProperty("background");
});
Here is the full code -<html>
<head>
<title>ActiveWidgets Examples</title>
<style>body {font: 12px Tahoma}</style>
<script src="../../runtime/lib/aw.js"></script>
<link href="../../runtime/styles/xp/aw.css" rel="stylesheet"></link>
</head>
<body>
<xml id="xmlDataIsland">
<records>
<r bc="#ff0000" fc="#000000" ft="Arial" fs="" >
<Country>Mexico</Country>
<Calls>3</Calls>
<ASR>0</ASR>
<PDD>0</PDD>
<ALOC>0</ALOC>
<More>+</More>
</r>
<r bc="#ff0000" fc="#000000" ft="Arial" fs="" >
<Country>Afghanistan</Country>
<Calls>2</Calls>
<ASR>0</ASR>
<PDD>1</PDD>
<ALOC>0</ALOC>
<More>+</More>
</r>
<r bc="#ff0000" fc="#000000" ft="Arial" fs="" >
<Country>Haiti</Country>
<Calls>23</Calls>
<ASR>0</ASR>
<PDD>0</PDD>
<ALOC>0</ALOC>
<More>+</More>
</r>
</records>
</xml>
<script>
var table = new AW.XML.Table;
var xml = document.getElementById("xmlDataIsland");
table.setColumns(["Country", "Calls", "ASR", "PDD", "ALOC", "@bc", "@fc", "@ft"]);
table.setXML(xml);
var obj = new AW.UI.Grid;
obj.setId("myGrid");
obj.setColumnCount(8);
obj.setRowCount(3);
obj.setCellModel(table);
obj.defineRowProperty("background", function(r){
return this.getCellText(5, r); // return 'background' column
});
var myRow = new AW.Grid.Row;
myRow.setStyle("background", function(){
return this.getRowProperty("background");
});
obj.setRowTemplate(myRow);
document.write(obj);
</script>
</body>
</html>
