Grid subclass that holds its own data doesn't work
I've created a subclass of the grid widget that does several things (i.e. sets default alternate row colors, allows rows to expand/collapse) BUT one of the main things I wanted it to do was hold onto its own data and heading info. That way when there are multiple grids on a page each will know its own data rather my storing all of that data and keeping track of all that data I can then talk directly to each grid.
The problem is that, although my variables seem to hold onto the correct info for each grid, they do not display properly. The last grid's data is displayed for all of the grids and the only the first grid triggers actions (i.e. clicking on a row to select it is recognized by the first grid, but is displayed in the second).
Also, I get different results on the web page based upon when I have the "document.write(....)" in my code.
Once again, if I look at the js arrays that are holding the data for each of my instances the data looks correct, but they do not behave properly.
Any help is appreciated.
Here is my subclass (I removed most of the code, it works, but it is just to demonstrate my problem) and a down and dirty file to try it out and demonstrate the problems:
--------------HERE IS MY SUBCLASS-------------------------
PromiaGrid.prototype = new Active.Controls.Grid();
PromiaGrid.prototype.constructor = PromiaGrid;
PromiaGrid.superclass = Active.Controls.Grid.prototype;
//Constructor
function PromiaGrid() {
this.dataForGrid = [['no data']];
this.headersForGrid = ['no data'];
this.setDataAndHeadings(this.dataForGrid, this.headersForGrid);
this.init();
}
//Initialize
PromiaGrid.prototype.init = function() {
this.setDataAndHeadings(this.dataForGrid, this.headersForGrid);
this.setDataProperty("text", function(i, j){return this.dataForGrid[i][j]});
this.setColumnProperty("text", function(i){return this.headersForGrid[i]});
//workaround for model proxy bug
this._DataProxy = null;
this._RowProxy = null;
};
//Set Data and/or Headings
PromiaGrid.prototype.setDataAndHeadings = function(someData, someHeadings) {
this.dataForGrid = someData;
this.headersForGrid=someHeadings;
this.setRowProperty("count",this.dataForGrid.length);
this.setColumnProperty("count",this.headersForGrid.length);
this.refresh();
}
---------------------------------------------------
-----------HERE IS CODE TO DEMONSTRATE THE PROBLEMS NOTE YOU'LL PROBLY NEED TO ADJUST THE PATHS TO THE CSS AND JS FILES---------
<head>
<!-- stylesheet(s) for the grid -->
<link href="../../runtime/styles/classic/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="../../runtime/lib/grid.js"></script>
<script src="../../runtime/lib/promia_grid_1.js""></script>
<style> .active-controls-grid {height: 60px; font: menu;} </style>
</head>
<script>
grid=new PromiaGrid();
grid.setDataAndHeadings([['AAAAAAAAAAAAAAAAAAAAAAAA'],['ZZZZZZZZZZZZZZZZZZZZZZZZ']],['col A'],true);
document.write("THIS GRID SHOULD CONTAIN A's in the first row, not B's AND THE SECOND ROW IS MISSING<BR>");
document.write("HERE IS THE DATA: " + grid.dataForGrid +"<BR>");
document.write(grid.toString()); //<--- THIS GRID WILL SHOW 'BBBBBBBBB's in the first row instead of 'AAAAAA's ???
document.write("<BR>");
var grid1=new PromiaGrid();
grid1.setDataAndHeadings([['BBBBBBBBBBBBBBBBBBBBBBBB']],['col B'],true);
document.write("THIS GRID LOOKS RIGHT BUT TRY CLICKING ON THE ROW THAT IS DISPLAYED<BR>");
document.write("HERE IS THE DATA: " + grid1.dataForGrid +"<BR>");
document.write(grid1.toString()) //<------This GRID WILL LOOK THE WAY WE EXPECT IT TO LOOK, BUT TRY CLICKING A ROW
document.write("<BR>");
</script>
<BODY>
<script>
document.write("THE FIRST GRID (ABOVE) SHOULD LOOK LIKE THIS. I HAVEN'T CHANGED THE DATA AND AM USING <BR>");
document.write("THE SAME 'document.write(grid)' THAT WAS USED TO DISPLAY THE FIRST GRID, SO WHY IS IT<BR>");
document.write("DIFFERENT ??? ALSO, TRY CLICKING ON THE FIRST ROW IN THIS GRID");
document.write("HERE IS THE DATA: " + grid.dataForGrid +"<BR>");
document.write(grid.toString())
document.write("<BR>");
document.write("LIKE THE 2nd GRID ABOVE THIS GRID LOOKS RIGHT BUT TRY CLICKING ON THE ROW THAT IS DISPLAYED<BR>");
document.write("HERE IS THE DATA: " + grid1.dataForGrid +"<BR>");
document.write(grid1.toString())
document.write("<BR>");
</script>
<BR>
So, the first and third grids should be the same <BR>
AND <BR>
the second and fourth grids should be the same <BR>
BUT THEY AREN'T
</BODY>
</HTML>
The problem is that, although my variables seem to hold onto the correct info for each grid, they do not display properly. The last grid's data is displayed for all of the grids and the only the first grid triggers actions (i.e. clicking on a row to select it is recognized by the first grid, but is displayed in the second).
Also, I get different results on the web page based upon when I have the "document.write(....)" in my code.
Once again, if I look at the js arrays that are holding the data for each of my instances the data looks correct, but they do not behave properly.
Any help is appreciated.
Here is my subclass (I removed most of the code, it works, but it is just to demonstrate my problem) and a down and dirty file to try it out and demonstrate the problems:
--------------HERE IS MY SUBCLASS-------------------------
PromiaGrid.prototype = new Active.Controls.Grid();
PromiaGrid.prototype.constructor = PromiaGrid;
PromiaGrid.superclass = Active.Controls.Grid.prototype;
//Constructor
function PromiaGrid() {
this.dataForGrid = [['no data']];
this.headersForGrid = ['no data'];
this.setDataAndHeadings(this.dataForGrid, this.headersForGrid);
this.init();
}
//Initialize
PromiaGrid.prototype.init = function() {
this.setDataAndHeadings(this.dataForGrid, this.headersForGrid);
this.setDataProperty("text", function(i, j){return this.dataForGrid[i][j]});
this.setColumnProperty("text", function(i){return this.headersForGrid[i]});
//workaround for model proxy bug
this._DataProxy = null;
this._RowProxy = null;
};
//Set Data and/or Headings
PromiaGrid.prototype.setDataAndHeadings = function(someData, someHeadings) {
this.dataForGrid = someData;
this.headersForGrid=someHeadings;
this.setRowProperty("count",this.dataForGrid.length);
this.setColumnProperty("count",this.headersForGrid.length);
this.refresh();
}
---------------------------------------------------
-----------HERE IS CODE TO DEMONSTRATE THE PROBLEMS NOTE YOU'LL PROBLY NEED TO ADJUST THE PATHS TO THE CSS AND JS FILES---------
<head>
<!-- stylesheet(s) for the grid -->
<link href="../../runtime/styles/classic/grid.css" rel="stylesheet" type="text/css" ></link>
<script src="../../runtime/lib/grid.js"></script>
<script src="../../runtime/lib/promia_grid_1.js""></script>
<style> .active-controls-grid {height: 60px; font: menu;} </style>
</head>
<script>
grid=new PromiaGrid();
grid.setDataAndHeadings([['AAAAAAAAAAAAAAAAAAAAAAAA'],['ZZZZZZZZZZZZZZZZZZZZZZZZ']],['col A'],true);
document.write("THIS GRID SHOULD CONTAIN A's in the first row, not B's AND THE SECOND ROW IS MISSING<BR>");
document.write("HERE IS THE DATA: " + grid.dataForGrid +"<BR>");
document.write(grid.toString()); //<--- THIS GRID WILL SHOW 'BBBBBBBBB's in the first row instead of 'AAAAAA's ???
document.write("<BR>");
var grid1=new PromiaGrid();
grid1.setDataAndHeadings([['BBBBBBBBBBBBBBBBBBBBBBBB']],['col B'],true);
document.write("THIS GRID LOOKS RIGHT BUT TRY CLICKING ON THE ROW THAT IS DISPLAYED<BR>");
document.write("HERE IS THE DATA: " + grid1.dataForGrid +"<BR>");
document.write(grid1.toString()) //<------This GRID WILL LOOK THE WAY WE EXPECT IT TO LOOK, BUT TRY CLICKING A ROW
document.write("<BR>");
</script>
<BODY>
<script>
document.write("THE FIRST GRID (ABOVE) SHOULD LOOK LIKE THIS. I HAVEN'T CHANGED THE DATA AND AM USING <BR>");
document.write("THE SAME 'document.write(grid)' THAT WAS USED TO DISPLAY THE FIRST GRID, SO WHY IS IT<BR>");
document.write("DIFFERENT ??? ALSO, TRY CLICKING ON THE FIRST ROW IN THIS GRID");
document.write("HERE IS THE DATA: " + grid.dataForGrid +"<BR>");
document.write(grid.toString())
document.write("<BR>");
document.write("LIKE THE 2nd GRID ABOVE THIS GRID LOOKS RIGHT BUT TRY CLICKING ON THE ROW THAT IS DISPLAYED<BR>");
document.write("HERE IS THE DATA: " + grid1.dataForGrid +"<BR>");
document.write(grid1.toString())
document.write("<BR>");
</script>
<BR>
So, the first and third grids should be the same <BR>
AND <BR>
the second and fourth grids should be the same <BR>
BUT THEY AREN'T
</BODY>
</HTML>
Frank Gualtieri
August 30,