EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Shon on January 21, 2015, 12:22:25 AM



Title: Add "OnSelect" event listner, without override the existing event listner
Post by: Shon on January 21, 2015, 12:22:25 AM
Hello dear friends,

I am trying to add another event listner for "onSelect" event without overriding the existing one, but i dont know thow to do this.

I initialize the combogrid like this:
jobjInput.combogrid({
            url: strUrl,
            mode: 'remote',
            .....
            onSelect: function() { ... }
});

and after that trying to add another event listner to the input like this:
jobjInput.combogrid({ onSelect: function() { ... } });

but if i do it in this way, the original "onSelect" event not raised.

apperantly there is another way to add event listener, can you please direct me what is the way? I searched the web without success

Thank u very much,
Shon


Title: Re: Add "OnSelect" event listner, without override the existing event listner
Post by: stworthy on January 21, 2015, 09:04:14 AM
Please try to extend the 'attachEvent' method for the combogrid component.
Code:
$.extend($.fn.combogrid.methods, {
attachEvent: function(jq, param){
return jq.each(function(){
var grid = $(this).combogrid('grid');
var opts = $(this).combogrid('options');
opts.handlers = opts.handlers || {};
var cbs = opts.handlers[param.event];
if (cbs){
cbs.push(param.handler);
} else {
cbs = [opts[param.event], param.handler];
}
opts.handlers[param.event] = cbs;
opts[param.event] = grid.datagrid('options')[param.event] = function(){
var target = this;
var args = arguments;
$.each(opts.handlers[param.event], function(i,h){
h.apply(target, args);
})
}
})
}
})

Call 'attachEvent' method to add your own event handler.
Code:
jobjInput.combogrid('attachEvent',{
  event: 'onSelect',
  handler: function(index,row){
    //...
  }
});


Title: Re: Add "OnSelect" event listner, without override the existing event listner
Post by: Shon on January 22, 2015, 03:07:45 AM
Thank you very very much stworthy, its works great!!!


Title: Re: Add "OnSelect" event listner, without override the existing event listner
Post by: Opan Mustopah on March 15, 2015, 08:33:05 AM
thanks stowrthy for the extended method. but it's not working when i try other event like 'onChange',

Code:
$(zone_id_dest.target).combogrid('attachEvent',{
          event: 'onChange',
          handler: function(nv,ov){
            console.log(nv);
          }
        });

i check the console but it won't show up.

thanks