EasyUI Forum
May 18, 2024, 12:14:51 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 a new Event  (Read 7559 times)
leela
Newbie
*
Posts: 29


View Profile Email
« on: February 09, 2015, 03:15:58 PM »

Hi,

 I want to add a new event to the datagrid like following, when singleSelect is true
  onBeforeUnselectAll: function(unselectIndex){},

 where I need to get the index of the record that just got unselected.

 The OnUnSelect/onUncheck/onBeforeUnselect/onBeforeUncheck do not get fired in this case

 I have added this code to the selectRow() in the jquery.easyui.all.js file

               if (opts.singleSelect){
         var unselectIndex = opts.finder.getTr(target, '', 'selected').attr("datagrid-row-index");
         if(unselectIndex!=undefined && unselectIndex!=index){
            opts.onBeforeUnselectAll.call(target, unselectIndex);
         }

         unselectAll(target);
         selectedRows.splice(0, selectedRows.length);
      }
         
But want to know if there is a better way of doing it without modifying the library itself.
Like just extend the datagrid API and add new events.

Appreciate any help
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #1 on: February 09, 2015, 07:01:30 PM »

If you only want to get the row to be selected, please try the 'onBeforeSelect' instead.
Code:
$('#dg').datagrid({
    onBeforeSelect: function(index,row){
        var selected = $(this).datagrid('getSelected');
        if (selected && selected != row){
            console.log(selected)
        }
    }
})
Logged
leela
Newbie
*
Posts: 29


View Profile Email
« Reply #2 on: February 10, 2015, 04:20:27 PM »

Hi,

 I am not trying to get the row to be selected.
 I am trying to get the row that will be unselected, when you select a row.

 Basically I have a Datagrid, with singleSelect option.
 Let us assume there are 3 rows. I selected row 2 (index - 1).
 Now when I select row 3(index - 2), row 2 gets unselected because of singleSelect:true option.
 I need to get the index of the row 2 that gets unselected, when I select row3.

 I expected onUnSelect to work, but looks like the onUnSelectAll is being triggered instead, because of singleSelect option
 So I need to get the index of all the records(basically only one record) that will be selected, before actually selecting the record clicked by User.

Hope I conveyed my requirement clearly.

 Please let me know if you have any suggestions
Logged
stworthy
Administrator
Hero Member
*****
Posts: 3581


View Profile Email
« Reply #3 on: February 10, 2015, 07:12:27 PM »

Please look at this example http://jsfiddle.net/zLobksxz/. You can get the unselected row before selecting a new row.
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!