EasyUI Forum
September 14, 2025, 08:06:43 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: onclick evento on a panel  (Read 7701 times)
korenanzo
Guest
« on: May 10, 2016, 07:58:37 AM »

Hi,

is it possible to enable events like "onClick" and "focus" on objects lie Panel and datagrid ?

I need to know that the user entered (click) in a grid even if it has no rows

Thanks,

RIc
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: May 11, 2016, 12:08:33 AM »

You can override the row click event handler. When click on a non-row area, the 'onClickRow' event is triggered with a '-1' parameter value passed to it.
Code:
(function($){
    var clickHander = $.fn.datagrid.defaults.rowEvents.click;
    $.fn.datagrid.defaults.rowEvents.click = function(e){
        var tr = $(e.target).closest('tr.datagrid-row');
        if (tr.length){
            clickHander.call(this, e);
        } else {
            var dg = $(e.target).closest('div.datagrid-view').children('.datagrid-f');
            var opts = dg.datagrid('options');
            opts.onClickRow.call(dg[0], -1);
        }
    }
})(jQuery);
$(function(){
    $('#dg').datagrid({
        onClickRow: function(index,row){
            console.log('onClickRow:'+index)
        }
    })
})
Logged
korenanzo
Guest
« Reply #2 on: May 12, 2016, 08:15:27 AM »

nice solution, thanks stworthy,

but in the mean time I've found an alternative solution:


 $('#dg').datagrid('getPanel').bind({
            focus:function(e) {
                console.log(' for focus on grid')
         })
Logged
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!