EasyUI Forum

General Category => Bug Report => Topic started by: gasoline on March 26, 2013, 03:11:48 AM



Title: v1.3.2 datagrid deleteRow Bug
Post by: gasoline on March 26, 2013, 03:11:48 AM
idField:'objectID',
columns:[[
         {field:'username',title:'username',width:200,sortable:true},
         {field:'action',title:'',width:50,formatter:function(value,row,rowIndex){
            var $_buttons = $("<div><a href='#' class='easyui-linkbutton' onclick='OPT_SYSTEMUSER_REMOVE("
                        + row.objectID + ");'></a></div>");
            $_buttons.find('.easyui-linkbutton').linkbutton({plain:true,iconCls:"icon-remove"});
            return $_buttons.html();
         }}
      ]],
-------------------------------------------
notice: the field 'action'
-------------------------------------------
OPT_SYSTEMUSER_REMOVE = function( _objectID ){
   $('#dataTabAll').datagrid('selectRecord',_objectID);
   var row = $('#dataTabAll').datagrid('getSelected');
   var index = $('#dataTabAll').datagrid('getRowIndex',row);
   $('#dataTabAll').datagrid('unselectRow',index);
   $('#dataTabAll').datagrid('deleteRow',index);
};
------------------------------------------
Bug Desc:
When I remove the last one, tip:" Uncaught TypeError: Cannot read property 'action' of undefined  " And Remove successfully.


Title: Re: v1.3.2 datagrid deleteRow Bug
Post by: stworthy on March 26, 2013, 08:43:29 AM
To solve this issue, stop the event bubbling when clicking the linkbutton

Code:
onclick=\"OPT_SYSTEMUSER_REMOVE('"
                        + row.objectID + "');event.stopPropagation?event.stopPropagation():window.event.cancelBubble=true;\"

or delay the delete action

Code:
		OPT_SYSTEMUSER_REMOVE = function( _objectID ){
   $('#dg').datagrid('selectRecord',_objectID);
   var row = $('#dg').datagrid('getSelected');
   var index = $('#dg').datagrid('getRowIndex',row);
   $('#dg').datagrid('unselectRow',index);
   setTimeout(function(){
   $('#dg').datagrid('deleteRow',index);
   },0);
};


Title: Re: v1.3.2 datagrid deleteRow Bug
Post by: gasoline on March 26, 2013, 06:26:56 PM
tks, I selected the second way and It`s OK.
But I don`t know reason.

If it`s not bug. do I need to remove this topic?


Title: Re: v1.3.2 datagrid deleteRow Bug
Post by: stworthy on March 26, 2013, 06:41:17 PM
The updated datagrid plugin can be download from http://www.jeasyui.com/easyui/plugins/jquery.datagrid.js. Thus delay deleting action is not need.
Code:
OPT_SYSTEMUSER_REMOVE = function( _objectID ){
var index = $('#dg').datagrid('getRowIndex',_objectID);
$('#dg').datagrid('deleteRow',index);
};