简体   繁体   中英

Extjs 4.1 - Listerning in CellEditing plugin not working at second time

i define a with plugin CellEditing like

Ext.define('MyExample', {
        extend: 'Ext.tree.Panel',   
        id: 'example',
        alias: 'example',
        ....
        plugins: [
            Ext.create('Ext.grid.plugin.CellEditing', {
                clicksToEdit: 1,
                listeners: {
                    beforeedit: function(plugin, edit){
                        alert('don't run second time');
                    }
                }
            })
        ],
        ...

And i have a when i click this button will call below window (this window has treeGrid above) 当我单击此按钮时将在窗口下方调用(此窗口上方有treeGrid)

Ext.create('Ext.window.Window', {
title: 'Phân xử lý',
modal:true,
height: 500
width: 500
layout: 'border',
...
item[
 {
  title: 'example',
  region: 'center',
  xtype: 'example', // that here
  layout: 'fit'
 }
]

Everything working at first time but when i close the window at first time and click button to call window again then CellEditting still working but listeners not working ?
How to fix that thanks


Please see my example code in 查看我的示例代码
In first time when i click button. Everything working well like 在此处输入图片说明

But when i close Example window and open it again I try click to blocked cell again i get a bug like 在此处输入图片说明


How to fix this bug? thanks

The problem here is that you are using Ext.create inside the plugins array for the tree grid. This have the effect of creating it once and attaching the result adhoc to your defined class.

If you close the window, all the resources within the window are destroyed. The second time you instantiate the tree panel, the plugin is not there. Take a look at this fiddle : I see what your issue is. Take a look at http://jsfiddle.net/jdflores/E6Uss/1/

     {
        ptype : 'cellediting',
        clicksToEdit: 1,
        listeners: {
            beforeedit: function(plugin, edit){
                console.log('EDITOR');
                if (edit.record.get('block')) {
                    alert('this cell have been blocked');
                    return false;
                }
            }
        }
    }

You're recreating the window on every click of the button. This recreation may be messing with your configuration objects or destroying associations or references within them, or something similar. Try to reuse the window everytime by replacing your button code with something like:

    Ext.create('Ext.Button', {
        text: 'Click me',
        visible: false,
        renderTo: Ext.getBody(),

        handler: function(button) {
            if(!button.myWindow)
            {
                button.myWindow = Ext.create('Ext.window.Window', {
                   title: 'Example',
                   height     : 300,
                   width      : 500,
                   layout: 'border',
                   closeAction: 'hide',
                   items: [{            
                            region: 'center',
                            floatable:false,
                            layout:'fit',
                            xtype: 'example',
                            margins:'1 1 1 1'
                        }
                    ]
                 });
            }
            button.myWindow.show();
        }
    });

Maybe it needed complete the editing cell, try finish it:

...
beforeedit: function(plugin, edit){
     alert('don't run second time');
     plugin.completeEdit();
}

Sencha: CompleteEdit

I put together a working example here: http://jsfiddle.net/jdflores/6vJZf/1/

I think the problem with your column is that it's dataIndex is expecting that the editor value be a boolean type (because 'block' was set as datIndex instead of 'date'). I assume you are using the 'block' field just to identify which are blocked to be edited. I modified the fidle provided here: http://jsfiddle.net/jdflores/6vJZf/1/

       {
            text: 'Block Date',
            dataIndex: 'date',
            xtype: 'datecolumn',
            format: 'd/m/Y',
            editor: {
                xtype: 'datefield',
                allowBlank: true,
                format: 'd/m/Y'
            } 
        }

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM