:: Forum >>

Subclassing the Active.Controls.Grid

Alex,

I am trying to create a subclass of your grid that will initialize itself with alternating row colors and the absence of row numbers.

I tried creating a subclass as follows:

PromiaGrid =Active.Controls.Grid.subclass();

PromiaGrid.create = function(){
var obj = this.prototype;
var _super = this.superclass.prototype;
obj.setRowHeaderWidth("0px");
obj.alternateColors = ["#ffffcc", "#cccccc"];
obj.alternate = function(){ return obj.alternateColors[this.getProperty("row/order") % obj.alternateColors.length]; }
obj.getTemplate("row").setStyle("background", obj.alternate);
}
PromiaGrid.create();

BUT when I use this subclass the only thing that displays are the column headings. NOTE: if I comment out the "obj.alternate=function()...." line then all of the rows display but they are all the same color.

Any help is appreciated.

Frank
Frank Gualtieri
Thursday, January 6, 2005
Update.... I've tried this a few different ways BUT it seems that what I said above, is incorrect. It is not the line "obj.alternate=function()..." that is giving me trouble, but rather the line use of

obj.getTemplate("row").setStyle......

that is giving me the problem. It seems that just using

obj.getTemplate("row")

alone causes only the headers to display in my grid. Even if I just put -> alert(obj.getTemplate("row")); <- in the create() method shown above I get only the headers to display.

Why is it that obj.getTemplate("row") causes my grid to only display headers when this that line appears in the create() method ???

HELP !!!!
Frank Gualtieri
Thursday, January 20, 2005
Frank,

your code is absolutely correct. I just found a bug in my data model implementation which has this side effect. The call to row template (same as data/item template) creates empty data models which are later used by a grid instance. As a workaround you have to clear _DataProxy and _RowProxy properties:

PromiaGrid = Active.Controls.Grid.subclass();

PromiaGrid.create = function(){

    var obj = this.prototype;
    var _super = this.superclass.prototype;
    obj.setRowHeaderWidth("0px");
    obj.alternateColors = ["#ffffcc", "#cccccc"];
    obj.alternate = function(){ return obj.alternateColors[this.getProperty("row/order") % obj.alternateColors.length]; }
    obj.getTemplate("row").setStyle("background", obj.alternate);

    // workaround for model proxy bug
    obj._DataProxy = null;
    obj._RowProxy = null;

}

PromiaGrid.create();
Alex (ActiveWidgets)
Thursday, January 20, 2005
Alex,

Thanks a million. I'll give the workaround a shot ASAP.

I plan on modifying the "row selection" methods.

I am writing an application that will use a master/detail - like scenario and I expand the rows to display details.

I am having problems keeping my colors in order with that code (after clicking and expanding a row, if I then click on a header to sort, all of the rows become the same color and when I contract the row it sometimes returns to its original color and sometimes not even though i think I'm resetting that color.)

To see the code I am using go here:
http://www.secretagentsband.com/aw/examples/grid/testRowExpansion.html

I actually have a more recent version of this code that I haven't uploaded yet. The code there does not demonstrate the color problem I am having it simply shows the row expansion.

Frank
Frank Gualtieri
Tuesday, January 25, 2005
Alex,

Just an update to let you know that your work around worked.

Frank Gualtieri
Frank Gualtieri
Tuesday, January 25, 2005
Why the creation of this var?

var _super = this.superclass.prototype;

Is it required in order to subclass from the grid? Would this be true of future UI controls?
Jim Hunter
Monday, August 29, 2005
Jim,

I believe the _super variable is there so that we could override methods in the superclass but use that variable to perform the superclasses version of the method as well.

For instance, the superclass may have method abc() and the subclass wants to do everything that the superclasses version did, then do some of its own processing.

I believe this is accomplished like this:

function abc() {
_super.abc();
---->stuff the subclass wants to do goes here<-----
}
Frank Gualtieri
Tuesday, August 30, 2005
Thanks,

Thats what I thought it was used for but sunce it wasn't used in the posted code I wasn't sure if it was needed or declared 'just in case it was needed later'.

Thanks again
Jim Hunter
Tuesday, August 30, 2005

This topic is archived.


Back to support forum

Forum search