extjs gridpanel:当GridPanel窗口再次显示时,ColumnModel变为null

时间:2011-11-21 17:08:43

标签: extjs undefined gridpanel

我使用预先配置的ColumnModel和Store定义了一个GridPanel,并将此GridPanel放在Ext.Window中;当这个窗口显示时,它工作正常,但是,如果我关闭它并再次显示它,GridPanel的ColumnModel变为null,以便无法正确呈现此GridPanel。

更新(所有代码)

 var stSummary = new Ext.data.JsonStore({ //define the store for Summary_Grid
        fields : [
        {
            name: 'recID'
        }, {
            name : 'name',
        }],
        data: []
    });

var colModelSummary = { //define the ColumnModel for Summary_Grid
    columns:
    [
        {
            header : "ID",
            width : 50,
            sortable : true,
            menuDisabled: true,
            dataIndex : 'recID'
        },
        {
            header : "Name",
            width : 100,
            sortable : true,
            menuDisabled: true,
            dataIndex : 'name'
        }
    ]
};

var reportConfig = {
    id : 'Report_Window',
    width : 250,
    floating : true,
    style : {
        opacity : 0.7,
    },
    title : "Report",
    layout: 'fit',
    items : [{
        xtype: 'tabpanel',
        id: 'Report_Tab',
        height: 200,
        activeTab: 1,
        items: 
        [
            {
                xtype : 'grid',
                store : stSummary,
                colModel : new Ext.grid.ColumnModel(colModelSummary),
                stripeRows : true,
                id : "Summary_Grid",
                title : "Summary at",
                sm : new Ext.grid.RowSelectionModel({
                    singleSelect : true
                }),
                listeners: {
                    'beforerender': function() {
                        console.log(this.getColumnModel().getColumnCount());
                    }
                }
            }, 
            {
                xtype : 'form',
                id : 'Report_Form',
                title: 'Item Report',
                frame : true,
                labelAlign : 'left',
                bodyStyle : 'padding:2px',
                autoScroll: true,
                layout : 'column',
                items : []  
            }
        ]
    }],
    resizable : {
        dynamic : true
    }
};
var reportWindow = new Ext.Window(reportConfig);

reportWindow.show();

document.onclick = myClickHandler;


    function myClickHandler() {
      if(!Ext.getCmp('Report_Window')) {
        var reportWindow = new Ext.Window(reportConfig);
      }

      Ext.getCmp('Report_Window').show();
    }
});

和错误:

Uncaught TypeError: Cannot read property 'length' of undefined
Ext.grid.ColumnModel.Ext.extend.getColumnCount                  ext-all.js:11

1 个答案:

答案 0 :(得分:0)

我实际上只是将您的代码粘贴到我的应用程序中。我最后添加了reportWindow.show() - 它有效!不确定可能出现什么问题,你能展示所有代码吗?

请注意,它可能是一个关闭/隐藏问题,您每次都重新创建窗口吗?

修改

尝试将closeAction: 'hide'设置为您的窗口配置。

检查以获取详细信息:

http://docs.sencha.com/ext-js/3-4/#!/api/Ext.Window-cfg-closeAction

编辑#2:

我再次测试了你的代码,它再次运行!我只纠正了几个额外的逗号 - 我的resharper建议它。 (这可能会导致IE中的问题)然后我把它推入Ext.onReady - 它的工作原理! Ext.version =='3.2.1'

检查整个代码:

Ext.onReady(function() {
    var stSummary = new Ext.data.JsonStore({
//define the store for Summary_Grid
            fields: [
                {
                    name: 'recID'
                }, {
                    name: 'name'
                }],
            data: []
        });

    var colModelSummary = {
//define the ColumnModel for Summary_Grid
        columns:
            [
                {
                    header: "ID",
                    width: 50,
                    sortable: true,
                    menuDisabled: true,
                    dataIndex: 'recID'
                },
                {
                    header: "Name",
                    width: 100,
                    sortable: true,
                    menuDisabled: true,
                    dataIndex: 'name'
                }
            ]
    };

    var reportConfig = {
        id: 'Report_Window',
        width: 250,
        floating: true,
        style: {
            opacity: 0.7
        },
        title: "Report",
        layout: 'fit',
        items: [{
            xtype: 'tabpanel',
            id: 'Report_Tab',
            height: 200,
            activeTab: 1,
            items:
                [
                    {
                        xtype: 'grid',
                        store: stSummary,
                        colModel: new Ext.grid.ColumnModel(colModelSummary),
                        stripeRows: true,
                        id: "Summary_Grid",
                        title: "Summary at",
                        sm: new Ext.grid.RowSelectionModel({
                            singleSelect: true
                        }),
                        listeners: {
                            'beforerender': function() {
                                console.log(this.getColumnModel().getColumnCount());
                            }
                        }
                    },
                    {
                        xtype: 'form',
                        id: 'Report_Form',
                        title: 'Item Report',
                        frame: true,
                        labelAlign: 'left',
                        bodyStyle: 'padding:2px',
                        autoScroll: true,
                        layout: 'column',
                        items: []
                    }
                ]
        }],
        resizable: {
            dynamic: true
        }
    };
    var reportWindow = new Ext.Window(reportConfig);

    reportWindow.show();

    document.onclick = myClickHandler;


    function myClickHandler() {
        if (!Ext.getCmp('Report_Window')) {
            reportWindow = new Ext.Window(reportConfig);
        }

        Ext.getCmp('Report_Window').show();
    }
});