EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: mzeddd on October 30, 2012, 12:32:48 PM



Title: reload on treegrid element
Post by: mzeddd on October 30, 2012, 12:32:48 PM
Hi,

I'm trying to call 'reload' method on treegrid data item to load new data.
It looks like it is not working or I use it in wrong way.

I don't want to post my code here but the idea is following:

0) Create treegrid
1) Load only root elements (level 1)
2) Expand any root item (it loads data for level 2 connected to this 'root' item)
3) Do some updates for 'selected' item
4) run reload like this:
Code:
$('#myTg').treegrid('reload',id);

treegrid gets data from PHP script where in the beginning I have the following line
Code:
error_log("id=".$_POST['id']);

And returning to my steps above I have traces in error_log file:
0) N/A
1) id=  (empty) - it is OK
2) id=3 (any value) - it is OK
3) N/A
4) PHP script was not called

ERROR console (Opera) is empty.

I tried to do the same for datagrid and it was OK. The problem is in treegrid only I think.

Do I do smth wrong or it is real bug in treegrid?

//Valery


Title: Re: reload on treegrid element
Post by: stworthy on October 30, 2012, 08:22:14 PM
I suppose you want to dynamic load data when clicking the expand button. If so, please learn the tutorial below carefully.
http://www.jeasyui.com/tutorial/tree/treegrid3.php


Title: Re: reload on treegrid element
Post by: mzeddd on October 31, 2012, 06:46:38 AM
No, I'm using dynamic load when clicking the expand buttom on step 2

the problem is - I could not update already loaded item.


Title: Re: reload on treegrid element
Post by: stworthy on October 31, 2012, 10:46:50 AM
The reload method is valid for non-leaf nodes. Try selecting a non-leaf node and call reload method again, you will see the node id being posted successfully. If you only want to update a node, call update method instead.


Title: Re: reload on treegrid element
Post by: mzeddd on November 01, 2012, 03:30:20 AM
Sorry for stupid question but what is leaf node?

Is it line #1 or #2 on this picture?
(http://www.jeasyui.com/tutorial/tree/images/treegrid2.png)

In my case I would like to update #2 line with information from DB using "reload" method.


Title: Re: reload on treegrid element
Post by: stworthy on November 01, 2012, 06:56:12 AM
Line #1 is the non-leaf node(line) because it has children rows while line #2 is the leaf node(line).
Please call 'update' method to update the selected row with new information.
Code:
var row = $('#myTg').treegrid('getSelected');
if (row){
$.post('get_row.php',{id:row.id},function(data){
$('#myTg').treegrid('update',{
id:row.id,
row:data
});
});
}


Title: Re: reload on treegrid element
Post by: mzeddd on November 03, 2012, 11:56:35 AM
Hi stworthy,

Can you give me one move example?

I tried to modify demo/treegrid.html example with new function but I is not working as I want. It keeps old data even after I call 'update'.
Quote
function test(){
      var newData = [{
         code: '01022',
         name: 'test',
         addr: 'test',
         col4: 'test'
      }];
      $('#test').treegrid('update',{
         id:'01022',
         row:newData
      });
   }

Thanks.


Title: Re: reload on treegrid element
Post by: stworthy on November 05, 2012, 07:47:22 AM
Please correct your code.
Code:
$('#test').treegrid('update',{
id:'01022',
row:{
name:'test',
addr:'test'
}
});


Title: Re: reload on treegrid element
Post by: mzeddd on November 05, 2012, 09:07:17 AM
Hi stworthy.

Your last example pushed me into correct direction.

And the working code look like this:

Code:
$.post(url,{id:row.id},function(data){
$('#myTg').treegrid('update',{
id:row.id,
row:jQuery.parseJSON(data)
});
});

Thanks!