Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Extjs Grid - How to get width of column in renderer function

Tags:

extjs

extjs4.1

I have a gridpanel and one of my column like

 columns: [
        ...
        { text: 'Name',  dataIndex: 'name' , width: 200,
             renderer: function (value) {
                  // how to get width of this column (200)
                  //alert(this.width); // this is width of gridpanel
             }
        }
        ...
 ],

how to get width of this column thanks.

like image 216
DeLe Avatar asked Mar 22 '23 04:03

DeLe


1 Answers

Fairly certain this isn't the ideal way to do it, but it works. There are lots of other values passed to the renderer function besides just the value. Via dom inspection, this will get you the column width, but I don't think it's something I would trust to work as they update ExtJS:

renderer: function (value, metaData, record, rowIndex, colIndex, store, view) {
    return view.ownerCt.columns[colIndex].getWidth();
}

Alternatively, you could use component query to get the grid panel view, use the row index to find the column, and then get it's width the same way:

renderer: function (value, metaData, record, rowIndex, colIndex, store, view) {
        var grid = Ext.ComponentQuery.query('#gridId')[0];
        return grid.columns[colIndex].getWidth();
    }

I really don't know what is the better option in this case, and don't really know why they pass the gridview rather than the gridpanel as the view in the renderer function. In any case, this should get you started, good luck.

like image 88
Stephen Tremaine Avatar answered Apr 26 '23 09:04

Stephen Tremaine