<style>
.aw-grid-view .aw-grid-view {
height: auto;
}
</style>
<script>
AW.Tree.Grid = AW.Grid.Control.subclass();
AW.Tree.Grid.create = function(){
var obj = this.prototype;
obj.onGroupTemplateChanged = function(group){
group.mapTemplate("content", "rows");
group.mapTemplate("item", "row");
group.mapModel("view", "row");
return true;
};
obj.defineTemplate("group", new AW.Tree.Group);
obj.onRowsTemplateChanged = function(rows){
rows.mapTemplate("item", function(i){return this.$owner.getGroupTemplate(i)});
rows.mapModel("view", "row");
return true;
};
obj.setRowsTemplate(new AW.Grid.Rows);
obj.setTemplate("cell", new AW.Tree.Item, 0);
obj.getContentTemplate().mapTemplate("panel", function(i){
switch(i){
case 0: return this.getHeadersTemplate();
case 1: return this.getGroupTemplate(0);
case 2: return this.getFootersTemplate();
}
});
obj.defineRowProperty("expanded", false);
obj.getCellTemplate(0).mapModel("view", function(p){
return this.$owner.getRowProperty(p, this.$1);
});
obj.onTreeSignClicked = function(src, i, j){
var expanded = this.getRowExpanded(j);
this.setRowExpanded(!expanded, j);
this.getGroupTemplate(j).refresh();
};
obj.onScrollLeftChanged = function(x){
var e1 = this.getGroupTemplate(0).element();
if (e1) {e1.parentNode.scrollLeft = x}
};
obj._sortController = {};
obj.setVirtualMode(false);
};
</script>
<script>
var tree = {
0: [1, 2, 3, 4],
1: [5, 6],
2: [7],
3: [8],
4: [9]
}
var obj = new AW.Tree.Grid;
obj.setCellText(function(col, row){return col + "." + row});
obj.setHeaderText("header");
obj.setColumnCount(10);
obj.setRowCount(function(i){return tree[i] ? tree[i].length : 0});
obj.setRowIndices(function(i){return tree[i]});
document.write(obj);
</script>
obj.onCellClicked = function(event, column, row) {
if (column == 1) { // we clicked an expand/collapse
// toggle myExpRows[row]
myExpRows[row] = ( (myExpRows[row] == 1) ? 0 : 1);
// move through rows and generate visible rows array
row = 0;
//var rows = "";
arr = new Array();
var showL1 = false;
var showL2 = false;
while( row <= myRowType.length ) {
// if it is of row type = 0, show it
if ( myRowType[row] == 0 )
//rows = rows + "," + row;
arr.push( row );
if ( myRowType[row] == 1 && showL1 )
//rows = rows + "," + row;
arr.push( row );
if ( myRowType[row] == 2 && showL2 )
//rows = rows + "," + row;
arr.push( row );
// if the root is set to expanded, then show any first level nodes below it
if ( myRowType[row] == 0 && myExpRows[row] == 1 )
{ showL1 = true; }
if ( myRowType[row] == 0 && myExpRows[row] == 0 )
{ showL1 = false; showL2 = false; }
if ( myRowType[row] == 1 && myExpRows[row] == 1 && showL1 )
{ showL2 = true; }
if ( myRowType[row] == 1 && myExpRows[row] == 0 )
{ showL2 = false; }
row++;
}
//alert( arr.join() );
if (arr.length > 0) {
obj.setRowCount(arr.length);
obj.setRowIndices(arr);
}
}
};
This topic is archived.