1. #1
    Sencha - Community Support Team mankz's Avatar
    Join Date
    Nov 2007
    Location
    Helsingborg, Sweden
    Posts
    2,454
    Vote Rating
    48
    mankz is a jewel in the rough mankz is a jewel in the rough mankz is a jewel in the rough

      0  

    Default Access the grid in a column renderer

    Access the grid in a column renderer


    Is there an easy way to access the grid object in a column renderer function? Currently I'm doing an override which I would gladly not do...

    Code:
    Ext.override(Ext.grid.GridView, {
        doRender : function(cs, rs, ds, startRow, colCount, stripe){
            var ts = this.templates, ct = ts.cell, rt = ts.row, last = colCount-1;
            var tstyle = 'width:'+this.getTotalWidth()+';';
                    var buf = [], cb, c, p = {}, rp = {tstyle: tstyle}, r;
            for(var j = 0, len = rs.length; j < len; j++){
                r = rs[j]; cb = [];
                var rowIndex = (j+startRow);
                for(var i = 0; i < colCount; i++){
                    c = cs[i];
                    p.id = c.id;
                    p.css = i == 0 ? 'x-grid3-cell-first ' : (i == last ? 'x-grid3-cell-last ' : '');
                    p.attr = p.cellAttr = "";
                    p.value = c.renderer(r.data[c.name], p, r, rowIndex, i, ds, this.grid);
                    p.style = c.style;
                    if(p.value == undefined || p.value === "") p.value = "*";
                    if(r.dirty && typeof r.modified[c.name] !== 'undefined'){
                        p.css += ' x-grid3-dirty-cell';
                    }
                    cb[cb.length] = ct.apply(p);
                }
                var alt = [];
                if(stripe && ((rowIndex+1) % 2 == 0)){
                    alt[0] = "x-grid3-row-alt";
                }
                if(r.dirty){
                    alt[1] = " x-grid3-dirty-row";
                }
                rp.cols = colCount;
                if(this.getRowClass){
                    alt[2] = this.getRowClass(r, rowIndex, rp, ds);
                }
                rp.alt = alt.join(" ");
                rp.cells = cb.join("");
                buf[buf.length] =  rt.apply(rp);
            }
            return buf.join("");
        }
    });

  2. #2
    Sencha - Architect Dev Team aconran's Avatar
    Join Date
    Mar 2007
    Posts
    8,185
    Vote Rating
    63
    aconran is just really nice aconran is just really nice aconran is just really nice aconran is just really nice aconran is just really nice

      0  

    Default


    No, there is currently no really clean way to access the grid from within a column renderer. This is how I've done it in the past without any overriding:
    Code:
    renderer: (function(v) {
        var txt = '<img src="{0}" />';
        var state = this.getStatus(v);
        return String.format(txt, state ? 'lock.png' : 'delete.png');
    }).createDelegate(this)
    When doing this from within a Grid subclass you will now have direct access to any of the grid methods/configurations/etc.

    I agree that we should add the ability to access the grid either through an argument or a this scope.
    Aaron Conran
    @aconran
    Sencha Architect Development Team