How to prevent itemclick event on check change in Ext Js Tree

旧城冷巷雨未停 提交于 2019-12-10 15:32:46

问题


I added two listeners 'check change' and 'item click' in Ext.tree.Panel. But i noticed that, when ever the check change occurs then it is also triggering item click event also. I wish to prevent this item click event.

    listeners : {
        checkchange: function(node, checked, eOpts){
            alert('this is check change');
        },
        itemclick : function(obj, record, item, index, e, eOpts){
            alert('this is item click');
        }
    }

This are the listeners in Ext tree. On check change i wish to get 'this is check change' this alert only. How it is possible ?


回答1:


You can use event getTarget method to check DOM of the checkbox. The complete solution is below:

onItemClick: function( self, record, item, index, eventObj, eOpts ) {
    var colIdx = eventObj.getTarget('.x-grid-cell').cellIndex;

    if (colIdx===0) { // Apply item event click to the first column only
        var node=self.getTreeStore().getNodeById(record.internalId);

        if (!eventObj.getTarget('.x-tree-checkbox',1,true)) {
            record.set('checked',!record.get('checked'));               
            this.fireEvent('checkchange', node, record.get('checked'));
        }
    } 
}



回答2:


Lame solution ! I was able to limit the script only to the 'itemclick'. Works well in ExtJs 5.1.1 and probably in all versions where css checkbox class name is 'x-tree-checkbox'

listeners : {
    itemclick : function(panel, record , item , index, event){
        var clazz = '';
        if(event.target.classList != null){
            clazz = event.target.classList[0];
        }
        if(clazz != 'x-tree-checkbox'){
            ...
        }
    }
}



回答3:


If you are clicking the checkbox to change its value the itemclick event will always fire before the checkchange event. If you dont wish for anything to happen on the itemclick event, simply dont define it (remove the listener).




回答4:


Have you tried to implement the 'beforeitemclick' event? it fires when you click the item, and inside this handler you can implement the checkchange.



来源:https://stackoverflow.com/questions/16101853/how-to-prevent-itemclick-event-on-check-change-in-ext-js-tree

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