3.2.0

Cell Format

I have, what seems to be (based on coming up empty in this form) a fairly different problem.

I am loading XML data into a table and then displaying that table in a grid. Fairly normal so far...But on top of that, I'm cross referencing the data in the table with a javascript array. If a record matches, I'd like to change the display of the grid cell to something different.

So far, what I have done is added code to table.response
var defaultResponse = table.response;   
    table.response = function(xml){  
        defaultResponse.call(this, xml);  
        
        for (z=0;z<table.getCount();z++){
            for (x=0;x<arrayCurrent.length;x++){
                if (table.getData(0,z) == arrayCurrent[x][0]){

                    
                    if (arrayCurrent[x][2] & 0x00001){
                        grd.setCellText("<span><img src=\"images/img.gif\" /></span>", 4, z); 
                    } else {
                        grd.setCellText("<span></span>", 4, z); 
                    }
                    if (arrayCurrent[x][2] & 0x00002){
                        grd.setCellText("<span><img src=\"images/img.gif\" /></span>", 2, z); 
                    } else {
                        grd.setCellText("<span></span>", 2, z); 
                    }
                    if (arrayCurrent[x][2] & 0x00004){
                        grd.setCellText("<span><img src=\"images/img.gif\" /></span>", 3, z); 
                    } else {
                        grd.setCellText("<span></span>", 3, z); 
                    }
                    if (arrayCurrent[x][2] & 0x00008){
                        grd.setCellText("<span><img src=\"images/img.gif\" /></span>", 5, z); 
                    } else {
                        grd.setCellText("<span></span>", 5, z); 
                    }
                    
                }
            }
        }
    }

This seems to work, but it seems very hacked together. Is there a better way? It seems like I should be able to do this with a format, but I cant seem to figure that one out.

On top of this, I am periodically refreshing my javascript array and the table which refreshes the grid. The problem is that if a row is removed the grd.setCellText set from the above code is still active. So the image set in row 0 col 5 is always there untill a full browser refresh.

Any help would be appreciated.

Thanks
Aaron
December 2,
Yes, I think there's a better way. I'll try to dig up some code later today and post it for you. It should also solve your refresh problem.

However, let's look at your current code.

Grid cell contents are already in a span, so its rather pointless adding another span around the contents.

So your code can be simplified to -
grd.setCellText("<img src='images/img.gif'>", 5, z) 
}
else
{
      grd.setCellText(" ", 5, z)

etc. although I would use a ternary operator instead -
grd.setCellText(arrayCurrent[x][2] & 0x00008 ? "<img src='images/img.gif'>" : " ", 5, z)

Are the lower 4 bits unique? I.e. its either 1, 2, 4 or 8 rather than values like 3, 5 etc.? If they are unique, you could use an array for your columns and access them via the unique bit values (i.e. [4, 2, 3, 5]).

That would reduce your 4 conditionals to 1 by using an array index. If not, then there's not much you can do apart from testing each of the bits.
Anthony
December 2,
Anthony,

Thanks for you input, but I ultimately made it work a different way. I added another bit to the value of the cell and created a custom format to check it and return what I need.
var custom = new AW.Formats.Number; 
custom.dataToText = function(d){
    if (Number(d) & 0x00002){
        if (Number(d) & 0x20000){
            return "<img src=\"images/img.gif\" />";
        } else {
            return "&bull;";
        }
    } else {
        return "";
    }
};


Thanks again.
Aaron
December 3,

This topic is archived.

See also:


Back to support forum