Hi,
There is a bug in jquery.treegrid.js in function remove (line 630).
After it is called, the html dom element is removed but the parent node's children array still contains the deleted node.
I fixed this bug, which is a mix-up between treeField and idField.
Additionally, in case there are no children left there was the same mix-up, and also the sub-tree of the parent was not removed.
So, here are my fixes:
/**
* remove the specified node
*/
function remove(target, idValue){
var opts = $.data(target, 'treegrid').options;
var tr = opts.finder.getTr(target, idValue);
tr.next('tr.treegrid-tr-tree').remove();
tr.remove();
var pnode = del(idValue);
if (pnode){
if (pnode.children.length == 0){
//fix - start
//tr = opts.finder.getTr(target, pnode[opts.treeField]);
tr = opts.finder.getTr(target, pnode[opts.idField]);
tr.next('tr.treegrid-tr-tree').remove();
//fix - end
var cell = tr.children('td[field=' + opts.treeField + ']').children('div.datagrid-cell');
cell.find('.tree-icon').removeClass('tree-folder').addClass('tree-file');
cell.find('.tree-hit').remove();
$('<span class="tree-indent"></span>').prependTo(cell);
}
}
setRowNumbers(target);
/**
* delete the specified node, return its parent node
*/
function del(id){
var cc;
var pnode = getParent(target, idValue);
if (pnode){
cc = pnode.children;
} else {
cc = $(target).treegrid('getData');
}
for(var i=0; i<cc.length; i++){
//fix - start
//if (cc[opts.treeField] == id){
if (cc[opts.idField] == id){
//fix - end
cc.splice(i, 1);
break;
}
}
return pnode;
}
}
EasyUI