javascript - ExtJS EditorGridPanel 显示错误

标签 javascript extjs cross-browser grid

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

问题如下:

我创建了一个窗口,它由 2 个 FormPanel 和它们之间的 EditorGridPanel 组成。 对于网格的 viewConfig,仅设置了“forceFit=true”,没有为 ColumnModel 设置样式或 View 选项。 只有每一列的对齐选项设置为“居中”。 ColumnModel 由 13 列组成,或多或少只有文本。 现在,我使用浏览器打开我正在使用的网站,然后打开窗口来测试 GUI。 当我尝试在单行中的单元格之间切换时,整个数据行向左移动, 这样第一个单元格就不再显示了。 将新行添加到网格后(通过添加按钮), View 将重置,每列的所有单元格将再次正确显示。 列标题和 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
                ]
            }
        ]
    });
}

最佳答案

首先,您似乎有一些 JavaScript 语法错误。我知道您只发布了一小段代码,但请尝试通过 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”,我怀疑编辑器可能会尝试使用您为每列设置的宽度。

看看这是否清除了任何东西。

关于javascript - ExtJS EditorGridPanel 显示错误,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4794693/

相关文章:

javascript - 旧版浏览器无法识别 ` in javascript

javascript - 检测鼠标指针是否在伪元素之上?

Javascript,可以检查 HTML <script> 标签中是否存在函数吗?

c# - 从 C# 传输到 ExtJS 时 JSON 数据发生变化

javascript - 如何将对象字面量中的重复代码放入函数中并使用参数进行调用?

html - 怪癖模式与 2011 年相关吗?

html - 如何使用 CSS 或 JavaScript 禁用文本选择?

javascript - jQuery 无限嵌套是否会降低性能?

javascript - 在文本框中选择建议项目时的 jQuery 事件?

javascript - 如何在 Sencha touch 中滑动多个屏幕