How do I disable a control in an ExtJS grid?

人走茶凉 提交于 2019-12-13 15:24:57

问题


I am using ExtJs 3.4. I have a checkbox control in an ExtJs Grid. I want to disable the checkbox control based on when a value in the store is equal to zero.

I have tried this and it does not disable it:

var colModel = new Ext.grid.ColumnModel(
    {
        columns: [
            { id: 'AircraftOid', header: "AircraftOid", width: 100, sortable: true, locked: true, dataIndex: 'AircraftOid', hidden: true },
            { id: 'nNumber', header: "N-#", width: 100, sortable: true, locked: true, dataIndex: 'NNumber' },
            { header: "Make", width: 150, sortable: true, dataIndex: 'Make' },
            { header: "Model", width: 150, sortable: true, dataIndex: 'Model' },
            { header: "Register",
                width: 55,
                sortable: true,
                dataIndex: 'Register',
                xtype: 'checkcolumn'
            }
        ],
        isCellEditable: function (col, row) {
            return false;
        }
    });

var grid = new Ext.grid.GridPanel({
        store: aircraftStore,
        cm: colModel,
        sm: new Ext.grid.RowSelectionModel({ singleSelect: true }),
        viewConfig: {
            forceFit: true
        },
        height: 100,
        split: true,
        region: 'north'
    });

Thanks in advance.


回答1:


Your thought was right. But...

First, you're overriding column model's isCellEditable method to prevent editing. But Grid doesn't calls that method. It only works on EditorGrid.

Second, Ext.ux.grid.CheckColumn doesn't handle any editable features, because it's not an editor, it's just a column.

So for my project i modified it to act as a editor and added the readOnly property to prevent editing on normal Grids. If you set readOnly to true, it'll not be clickable anymore.

Ext.ux.grid.CheckColumn = Ext.extend(Ext.grid.Column, {
    processEvent : function(name, e, grid, rowIndex, colIndex) {
        if ( !this.readOnly && name == 'mousedown' ) {
            grid.stopEditing();
            var record = grid.store.getAt(rowIndex);
            var cm = grid.getColumnModel();
            var edit_e = {
                grid: grid,
                record: record,
                field: this.dataIndex,
                value: record.data[this.dataIndex],
                row: rowIndex,
                column: colIndex,
                cancel: false
            };
            if ( grid.fireEvent( 'beforeedit', edit_e ) !== false && !edit_e.cancel ) {
                record.set( this.dataIndex, !record.data[this.dataIndex] );
                edit_e.cancel = null;
                grid.fireEvent( 'afteredit', edit_e );
            }
            return false;
        } else {
            return Ext.grid.ActionColumn.superclass.processEvent.apply(this, arguments);
        }
    },

    editable : false,

    readOnly : false,

    renderer : function(v, p, record){
        p.css += ' x-grid3-check-col-td'; 
        return String.format('<div class="x-grid3-check-col{0}">&#160;</div>', v ? '-on' : '');
    },

    init: Ext.emptyFn
});

Ext.preg('checkcolumn', Ext.ux.grid.CheckColumn);

Ext.grid.CheckColumn = Ext.ux.grid.CheckColumn;

Ext.grid.Column.types.checkcolumn = Ext.ux.grid.CheckColumn;


来源:https://stackoverflow.com/questions/11440216/how-do-i-disable-a-control-in-an-extjs-grid

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!