EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Afract on September 28, 2016, 03:21:40 AM



Title: How to force reload of node in treegrid on re-expand node ?
Post by: Afract on September 28, 2016, 03:21:40 AM
Hello,

I'm using treegrid with dynamic loading, it works great.

I've one little question with it : by default, when the user collapses and re-expands a node previously expanded once, the treegrid displays the content previously fetched from the server instead of doing a new call.

This "keep in memory" feature is very good to avoid in some case to call the server again, but in my own case I would like to be able to force the treegrid to refresh the node content everytime is closed and re-expanded with updated server data.

This is probably easy to achieve but I have been unable to figure how, I've tried a few things in "onExpand" handler (like calls to "reload", "update"...) but none of them behaves like I would.

Thank you!


Title: Re: How to force reload of node in treegrid on re-expand node ?
Post by: stworthy on September 28, 2016, 07:48:36 AM
Please refer to the code below:
Code:
$('#tg').treegrid({
onExpand: function(row){
if (row._loaded){
row._loaded = false;
$(this).treegrid('reload', row.id);
} else {
row._loaded = true;
}
}
});


Title: Re: How to force reload of node in treegrid on re-expand node ?
Post by: Afract on October 04, 2016, 07:54:03 AM
Hello,

Thank you, it works as desired. I just had to adapt a few things like the "id" property of "row" to make it work.

But I noticed one problem : the node is refreshed, but when now when I expand a node it triggers two POSTs on the data service. Exactly the same post twice.
This seems to happen only the very first time I open a node, but not for the other times but I'm not sure.

I'm using jQuery EasyUI 1.5 and jQuery 3.1 with last version of Firefox.

Are you able to reproduce the problem ? Let me know if you need more of my code.


Title: Re: How to force reload of node in treegrid on re-expand node ?
Post by: stworthy on October 05, 2016, 04:37:53 AM
Please try the updated code posted in previous topic.


Title: Re: How to force reload of node in treegrid on re-expand node ?
Post by: Afract on October 12, 2016, 02:26:38 AM
Hello,
This time it works perfectly, thanks :).

I think it's an useful ability, so can I politely suggest to add it as a feature (via a new option) in an future release ? :)

Thank you again !