EasyUI Forum
September 15, 2025, 07:46:26 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: extend datagrid onSelect event  (Read 9577 times)
CLKG
Guest
« on: October 20, 2015, 12:05:22 AM »

Hi, since datagrid doesn't have the "onSelectChanged" event, I try to write one myself.
I just extend the default "onSelect" event and keep a "selectedIndex" value in the opts, when the selectedIndex changes, trigger the onSelectChanged event.
But I realize that whenever I wanna use the onSelect event, I need to paste this code snippet everywhere...
So is there any better way?

Plus, I think it's better to add a "getSelectedIndex" method to datagrid, instead of getRowIndex + getSelected.
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: October 20, 2015, 01:43:45 AM »

Please try this code to trigger the 'onSelectChanged' event. You only need to include the code to your page and do not need to paste it everywhere.
Code:
(function($){
  $.extend($.fn.datagrid.defaults, {
    onSelect: function(index, row){
      var opts = $(this).datagrid('options');
      if (opts.onSelectRow){
        opts.onSelectRow.call(this, index, row);
      }
      if (opts.selectedIndex != index){
        opts.selectedIndex = index;
        if (opts.onSelectChanged){
          opts.onSelectChanged.call(this, index, row);
        }
      }
    }
  })
})(jQuery);
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!