EasyUI Forum
May 16, 2024, 04:49:44 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News:
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Add "OnSelect" event listner, without override the existing event listner  (Read 8318 times)
Shon
Newbie
*
Posts: 4


View Profile Email
« 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
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 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){
    //...
  }
});
Logged
Shon
Newbie
*
Posts: 4


View Profile Email
« Reply #2 on: January 22, 2015, 03:07:45 AM »

Thank you very very much stworthy, its works great!!!
Logged
Opan Mustopah
Full Member
***
Posts: 164


Indonesia


View Profile Email
« Reply #3 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
Logged

-- Bajak Otak --
*** Sorry for my bad english :3 ***
--JeasyUI version 1.4--
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.18 | SMF © 2013, Simple Machines Valid XHTML 1.0! Valid CSS!