EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: zhangjian420 on December 23, 2014, 07:48:56 AM



Title: treegrid remove event
Post by: zhangjian420 on December 23, 2014, 07:48:56 AM
t.treegrid("remove",id);
         var data = t.treegrid("getData");
         console.info(data);

This is my code . After it is called, the html dom element is removed but when I invoke the  'getData' method, the result also contains the removed data。

easyui version 1.4 。 waiting.....


Title: Re: treegrid remove event
Post by: stworthy on December 23, 2014, 08:46:28 AM
The 'remove' method can remove the specified node. Please check your code carefully. If your issue continues, please provide an example to demonstrate your issue.


Title: Re: treegrid remove event
Post by: zhangjian420 on December 24, 2014, 06:31:26 AM
The 'remove' method can remove the specified node. Please check your code carefully. If your issue continues, please provide an example to demonstrate your issue.
Code:
function deleteSubject(id){
var t = $('#tt');
$.messager.confirm('提示', '确定删除该科目?', function(r){
if(r){
var data1 = t.treegrid("getData");
console.info(data1);
t.treegrid("remove",id);
var data = t.treegrid("getData");
console.info(data);
}
});

/*var footer = t.treegrid("getFooterRows");
var json = {};
json.total = 10;
json.rows = data;
json.footer = footer;
t.treegrid("loadData",json);*/
}


Title: Re: treegrid remove event
Post by: stworthy on December 24, 2014, 07:04:15 AM
Please confirm if you removed the node successfully. Here is the example http://jsfiddle.net/mgq8h4d2/. It works fine.


Title: Re: treegrid remove event
Post by: zhangjian420 on December 24, 2014, 07:38:07 AM
Please confirm if you removed the node successfully. Here is the example http://jsfiddle.net/mgq8h4d2/. It works fine.

Hello , The attachment is my example。
wait on line....

In my demo,when i delete the first node then it works fine. but when i delete the other nodes ,it doesn't work


Title: Re: treegrid remove event
Post by: stworthy on December 24, 2014, 09:08:27 PM
Your json data has the wrong format, please use the 'loadFilter' function to convert your original data to correct data format.
Code:
$('#tt').treegrid({
loadFilter:function(data,parentId){
function getRows(children){
var rows = [];
function setRows(pid, children){
$.map(children, function(row){
row._parentId = pid;
rows.push(row);
if (row.children && row.children.length){
setRows(row.id, row.children);
}
row.children = undefined;
});
}
setRows(null, children);
return rows;
}
data.rows = getRows(data.rows);
return data;
}
})


Title: Re: treegrid remove event
Post by: zhangjian420 on December 26, 2014, 05:47:34 AM
Your json data has the wrong format, please use the 'loadFilter' function to convert your original data to correct data format.
Code:
$('#tt').treegrid({
loadFilter:function(data,parentId){
function getRows(children){
var rows = [];
function setRows(pid, children){
$.map(children, function(row){
row._parentId = pid;
rows.push(row);
if (row.children && row.children.length){
setRows(row.id, row.children);
}
row.children = undefined;
});
}
setRows(null, children);
return rows;
}
data.rows = getRows(data.rows);
return data;
}
})

thank you very much!