extjs4 怎么取到所有columns的header 表头名

var MyPanelUi = Ext.extend(Ext.Panel, {
        title: '上市公司股价信息',        width: 764,        renderTo:'mainDiv',        initComponent: function() {            this.items = [                {                    xtype: 'form',                    title: '',                    layout: 'hbox',                    formId: 'searchFrm',                    bodyStyle: 'background:#d6e3f3; padding:10px;',                fieldDefaults: {                    labelAlign: 'right',                    labelWidth: 70,                    anchor: '100%'                },                    defaults: {                        margins: '5 40 0 0'                    },                    items: [                        {                            xtype: 'textfield',                            fieldLabel: '公司名称',                            name: 'userName',                            allowBlank: false                        },                        {                      xtype: 'numberfield',                      name: 'price',                      fieldLabel: '股价',                      value: 5,                      minValue: 0,                      maxValue: 50                        },                        {                            xtype: 'button',                            text: '查    询'                            //,iconCls:'searchBtn'                        }                    ]                },                {                    xtype: 'grid',                    title: '股价信息列表',                    id : 'mygrid',                    height: 323,                 store: ds,                    columns : [                          {                              id       :'company',                              text   : 'Company',                              flex: 1,                              sortable : true,                              dataIndex: 'company'                          },                          {                              text   : 'Price',                              width    : 75,                              sortable : true,                              dataIndex: 'price'                          },                          {                              text   : 'Change',                              width    : 75,                              sortable : true,                              renderer : change,                              dataIndex: 'change'                          },                          {                              text   : '% Change',                              width    : 75,                              sortable : true,                              renderer : pctChange,                              dataIndex: 'pctChange'                          },                          {                              text   : 'Last Updated',                              width    : 85,                              sortable : true,                              renderer : Ext.util.Format.dateRenderer('m/d/Y'),                              dataIndex: 'lastChange'                          },                          {                              text: 'Rating',                              width: 30,                              sortable: true,                              renderer: rating,                              dataIndex: 'rating'                          }                    ],                    bbar: {                           dock: 'bottom',                        xtype: 'pagingtoolbar',                        store: ds,                        pageSize: 25,                        displayInfo: true,                        displayMsg: '当前 {0} 到 {1} 条    共有 {2}条',                        emptyMsg: '没有可供显示的数据'                    },                    tbar: {                        xtype: 'toolbar',                        items: [                            {                                xtype: 'button',                          iconCls: 'add',                                text: '添加',                                handler: function () {                                var column=Ext.getCmp('mygrid').columns;                                 alert(column);                                //alert(Ext.getCmp('mygrid').column.getColumnCount());                                }                            },                            {                                xtype: 'button',                          iconCls: 'update',                                text: '修改'                            },                            {                                xtype: 'button',                          iconCls: 'remove',                                text: '删除'                            }                        ]                    }                }            ];            MyPanelUi.superclass.initComponent.call(this);        }    });
  1.  var column=Ext.getCmp('mygrid').columns; 
  2.                                 alert(column);

 

怎么取到所有columns的header 表头名

[code="java"]var column=Ext.getCmp('mygrid').getStore().fields;
alert(column);[/code]

或者循环columns,取出dataindex

下面给你个链接自己看看
http://stackoverflow.com/questions/1300483/how-do-i-get-column-
name-from-rowselection-in-an-extjs-grid

[color=red]If you want to get the column header, call "yourGrid.getColumnModel().getColumnHeader(colIndex)[/color]

[quote]或者循环columns,取出dataindex[/quote]

采取这种方式,应该可以,如果你的component没有设置store的话

[quote]是不是column.items.??可以取到key 或者value [/quote]
key 就相当于 dataIndex
value 是从store里面取出来的,store.data[dataIndex]

columns[i].text