【问题标题】:ExtJS EditorGridPanel display ErrorExtJS EditorGridPanel 显示错误
【发布时间】:2011-01-25 14:33:35
【问题描述】:

我的 Ext.Grid.EditorGridPanel 有问题,我目前使用的是 ExtJS 2.3.0,无法更改。 :-(

跟随问题:

我创建了一个由 2 个 FormPanel 和它们之间的 EditorGridPanel 组成的窗口。 对于网格的 viewConfig,只有“forceFit=true”设置,没有为 ColumnModel 设置样式或视图选项。 仅对于每一列,对齐选项设置为“居中”。 ColumnModel 由 13 列组成,或多或少只有文本。 现在我用浏览器打开我正在开发的网站并打开窗口来测试 GUI。 当我尝试在单行中的单元格之间切换时,整个数据行向左移动, 这样第一个单元格就不再显示了。 在向网格添加新行(通过添加按钮)后,视图会重置,并且每列的所有单元格都会再次正确显示。 列标题和 tbar 是固定的,并且始终正确呈现。

IExplorer 8.0x 是较旧的 Firefox 版本 (2.0x) 会出现此问题,但网格在 Firefox 3.6x 和 Safari 5.0x 上运行良好。 如果有人有类似的问题并得到解决或知道可能导致该问题的原因,请随时回答。 ;-) 提前谢谢了!

[编辑] 感谢评论,这里有一些来自完整源代码的修改源代码:

getTypeSelectionGrid: function() {
    this.gridRecord:  Ext.data.Record.create([
        {name:'id', type:'int'},
        {name:'start', type:'string'},
        {name:'end', type:'string'},
        {name:'mo', type:'boolean'},
        {name:'tu', type:'boolean'},
        {name:'we', type:'boolean'},
        {name:'th', type:'boolean'},
        {name:'fr', type:'boolean'},
        {name:'sa', type:'boolean'},
        {name:'su', type:'boolean'},
        {name:'type', type:'string'}
    ]);

    this.gridStore = new Ext.data.Store({
        baseParams: {
        },
        sortInfo: {field: 'id', direction: 'ASC'},
        proxy: new Ext.data.HttpProxy({
            url: '',
            method: 'post'
        }),
        reader: new Ext.data.JsonReader({
            root: 'data',
            totalProperty: 'totalCount',
            id: 'id'
        }, this.gridRecord)
    });

    var sm = new Ext.grid.RowSelectionModel({ singleSelect: true });

    var columnConfig = [];
    //auto incremented id column
    columnConfig.push({ 
        header: 'id',
        dataIndex: 'id',
        width: 50,
        editor: new Ext.form.TextField({
            anchor: '100%',
            allowBlank: false,
            disabled: true
        })
    });
    //start value for time range, values from '00:00' to '24:00' steps by second, here shorted to 2 options
    columnConfig.push({
        header: 'start',
        dataIndex: 'start',
        width: 70,
        align: 'center',
        editor: new Ext.form.ComboBox({
            store: new Ext.data.SimpleStore({
                fields: ['val', 'txt'],
                data : [['00:00', '00:00'],['24:00', '24:00']]
            }),
            displayField: 'txt',
            valueField: 'val',
            typeAhead: true,
            mode: 'local',
            triggerAction: 'all',
            selectOnFocus: true,
            saveRouting: true,
            forceSelection: true,
            anchor: '100%',
            allowBlank: false
        })
    });
    //same as above for end of time range, dataIndex 'end'

    //now 7 checkbox columns foreach weekday
    columnConfig.push({
        xtype: 'checkcolumn',
        header: 'mo',
        dataIndex: 'mo',
        align: 'center',
        width: 30
    }));
    //same as above for dataIndex 'tu', 'we', 'th', 'fr', 'sa' and 'su'

    //here simplified to SimpleStore, originally a remote store which gets the data
    //by a HttpProxy
    columnConfig.push({
        header: 'type',
        dataIndex: 'type',
        editor: new Ext.form.ComboBox({
            store: new Ext.data.SimpleStore({
                fields: ['val', 'txt'],
                data : [[1, 'type 1'],[2, 'type 2']]
            }),
            displayField: 'txt',
            valueField: 'txt',
            typeAhead: true,
            mode: 'local',
            triggerAction: 'all',
            selectOnFocus: true,
            saveRouting: true,
            forceSelection: true,
            anchor: '100%',
            allowBlank: false
        })
    });
    //then 2 plugins which have some functionality for the selected row
    //grid tested with and without both plugins, they are not the cause

    var cm = new Ext.grid.ColumnModel(columnConfig);
    cm.defaultSortable = false;

    //now the grid
    this.typeSelectionGrid = new Ext.grid.EditorGridPanel({
        store: this.gridStore,
        clicksToEdit: 1,
        autoHeight: true,
        cm: cm,
        sm: sm,
        viewConfig: {
            forceFit: true
        },
        tbar: [{
            text: 'add new row',
            cls: 'x-btn-text',
            scope: this,
            handler: function(){
                //adds a row with incremented id
            }
        }],
        listeners: {
            scope: this,
            show: function() {
                sm.selectFirstRow.defer(1000, selectionModel);
            }
        }
    });

    return this.typeSelectionGrid;
},

//the grid is then inserted between the Panels into the window component
//looks something like that
render: function() {

    var layoutFn = function(pnl) {
        pnl.ownerCt.ownerCt.doLayout.defer(Ext.isIE ? 300 : 0, pnl.ownerCt.ownerCt);
        pnl.doLayout.defer(Ext.isIE ? 500 : 200, pnl);
    };
    this.cardLayout.add({
        layout: 'border',
        border: false,
        bodyStyle: 'background-color: #fff',
        items: [
            {
                region: 'center',
                border: false,
                layout: 'column',
                autoScroll: true,
                defaults: {
                    columnWidth: 1,
                    bodyStyle: 'padding: 5px;',
                    border: false,
                    autoHeight: true,
                    layout: 'column',
                    defaults: {
                        columnWidth: 1
                    }
                },
                items: [
                    //first Ext.form.FormPanel with some TextFields
                    {
                        items: {
                            listeners: {
                                expand: layoutFn,
                                collapse: layoutFn
                            },
                            frame: true,
                            title: 'panel with a grid',
                            collapsible: true,
                            titleCollapse: true,
                            layout: 'fit',
                            autoHeight: true,
                            items: this.getTypeSelectionGrid()
                        }
                    }
                    //second Ext.form.FormPanel with some TextFields
                ]
            }
        ]
    });
}

【问题讨论】:

  • 如果您可以发布示例代码,也可以进行调试:) 干杯
  • thx Lionel,我在文章中添加了一些来源。

标签: javascript extjs cross-browser grid


【解决方案1】:

首先,您似乎遇到了一些 JavaScript 语法错误。我知道你只发布了你的代码的 sn-p,但尝试通过 JS Lint 运行整个事情。

对于初学者:

this.gridRecord:  Ext.data.Record.create([
    {name:'id', type:'int'},
    {name:'start', type:'string'},
    {name:'end', type:'string'},
    {name:'mo', type:'boolean'},
    {name:'tu', type:'boolean'},
    {name:'we', type:'boolean'},
    {name:'th', type:'boolean'},
    {name:'fr', type:'boolean'},
    {name:'sa', type:'boolean'},
    {name:'su', type:'boolean'},
    {name:'type', type:'string'}
]);

应该是:

this.gridRecord = Ext.data.Record.create([

虽然我不完全确定这会导致问题,但我看到您的列配置已分配给它们的宽度。即使您正在设置 viewConfig 属性“forceFit: true”,我怀疑编辑器可能会尝试使用您为每列设置的宽度。

看看这是否能解决任何问题。

【讨论】:

    【解决方案2】:

    谢谢,但是代码 sn-p 有复制和粘贴错误,gridRecord 是原始代码的全局属性。 我在修改代码时忽略了这一点,很抱歉造成混淆。

    现在我尝试了您的建议并找到了罪魁祸首: 似乎 IE 根本无法处理“forceFit”选项,我注释掉了该选项并 设置每列的宽度......它工作正常,没有列移动! 不,我插入了一个解决方法,首先我检查浏览器是否为 IE,如果不是,则“forceFit”选项设置为“true”,否则为“false”。

    非常感谢您的帮助!

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2011-03-28
      • 2011-07-31
      • 1970-01-01
      • 2011-09-15
      • 1970-01-01
      • 2011-02-20
      • 2012-06-29
      • 1970-01-01
      相关资源
      最近更新 更多