【问题标题】:How to disable grid cell in extJS grid while loading base on some row record data如何在基于某些行记录数据加载时禁用 extJS 网格中的网格单元
【发布时间】:2020-07-09 14:39:59
【问题描述】:

如何在基于某些 reacid 数据加载时禁用 extJS 网格中的网格单元。

我正在使用网格,我想根据记录数据禁用一个网格编辑器。这是我正在尝试的,但发生的是当任何单元格被禁用时,整个列单元格被禁用。

我的分类

{
    "header": "column 3",
    "tdCls":"editable-grid-cell",
    "dataIndex": "clumn3",
    "width":120,
    "renderer":"enableDisablecolumn3",
    "editor": {
      "xtype": "numberfield", 
      "bind": "{record.column3}",
      "disabled":false,
      "allowDecimals":true,     
      "decimalPrecision":5,
      "allowNegative": false,
      "maskRe": "/[0-9.-]/",
      "minValue": 0 
    }
}

我的渲染器方法。

enableDisablecolumn3:  function(value, metaData, record) {
        //debugger;
        let _this = this;
        var gridEditor = metaData.column.getEditor();
        if ('Yes' === record.data.column2&& ) {    
            gridEditor.setDisabled(true);    
        }
    } 

知道如何实现这一点。我只想禁用那个特定的单元格。

【问题讨论】:

  • 你用的是哪个版本的extjs和工具包?
  • ExtJS 6.5 我正在使用。

标签: javascript extjs


【解决方案1】:

您可以使用 beforeedit 事件。像这样的:

Ext.application({
    name: 'Fiddle',

    launch: function () {
        Ext.create('Ext.data.Store', {
            storeId: 'simpsonsStore',
            fields: ['name', 'email', 'phone'],
            data: [{
                name: 'Lisa',
                email: 'lisa@simpsons.com',
                phone: '555-111-1224'
            }, {
                name: 'Bart',
                email: 'bart@simpsons.com',
                phone: '555-222-1234'
            }, {
                name: 'Homer',
                email: 'homer@simpsons.com',
                phone: '555-222-1244'
            }, {
                name: 'Marge',
                email: 'marge@simpsons.com',
                phone: '555-222-1254'
            }]
        });

        Ext.create('Ext.grid.Panel', {
            title: 'Simpsons',
            store: Ext.data.StoreManager.lookup('simpsonsStore'),
            columns: [{
                header: 'Name',
                dataIndex: 'name',
                editor: 'textfield'
            }, {
                header: 'Email',
                dataIndex: 'email',
                flex: 1,
                editor: {
                    completeOnEnter: false,
                    field: {
                        xtype: 'textfield',
                        allowBlank: false
                    }
                }
            }, {
                header: 'Phone',
                dataIndex: 'phone'
            }],
            selModel: 'cellmodel',
            plugins: {
                cellediting: {
                    clicksToEdit: 1
                }
            },
            height: 200,
            width: 400,
            listeners: {
                beforeedit: function( editor, context, eOpts ) {
                    if(context.field === 'name' && context.value === "Marge") {
                        return false;
                    }
                }
            },
            renderTo: Ext.getBody()
        });
    }
});

【讨论】:

猜你喜欢
  • 1970-01-01
  • 2013-01-17
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-11
  • 1970-01-01
  • 2012-11-16
相关资源
最近更新 更多