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

梦想的初衷 提交于 2021-02-07 04:37:17

问题


i define a treeGrid 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 button when i click this button will call below window (this window has treeGrid above)

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

EDIT
Please see my example code in http://jsfiddle.net/E6Uss/
In first time when i click button. Everything working well like enter image description here

But when i close Example window and open it again I try click to blocked cell again i get a bug like enter image description here


How to fix this bug? thanks


回答1:


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;
                }
            }
        }
    }



回答2:


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();
        }
    });



回答3:


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

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

Sencha: CompleteEdit




回答4:


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'
            } 
        }


来源:https://stackoverflow.com/questions/17826876/extjs-4-1-listerning-in-cellediting-plugin-not-working-at-second-time

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