Extjs Grid - 如何在渲染器函数中获取列的宽度

DeL*_*eLe 4 extjs extjs4.1

我有一个gridpanel和我的专栏之一

 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
             }
        }
        ...
 ],
Run Code Online (Sandbox Code Playgroud)

如何获得此列的宽度谢谢.

小智 7

相当肯定这不是理想的做法,但它确实有效.除了值之外,还有许多其他值传递给渲染器函数.通过dom检查,这将获得列宽,但我不认为这是我信任的工作,因为他们更新ExtJS:

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

或者,您可以使用组件查询来获取网格面板视图,使用行索引查找列,然后以相同的方式获取它的宽度:

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

我真的不知道在这种情况下什么是更好的选项,并且不知道它们为什么通过gridview而不是gridpanel作为渲染器函数中的视图.无论如何,这应该让你开始,祝你好运.