EasyUI Forum

General Category => EasyUI for jQuery => Topic started by: Onegin on July 07, 2011, 01:30:23 PM



Title: treegrid dynamic load and grid refresh
Post by: Onegin on July 07, 2011, 01:30:23 PM
I use treegrid component and because of the number of records, i load branches dynamically via ID reference.
Problem is, that when I hit refresh, the appended id in uri is sent to server and it returns only that portion of records that is supposed to be that branch data...
My question is how can I load data dynamically to the treegrid and be able to refresh the whole grid without last used ?id=foo beying appended to grid url.


Title: Re: treegrid dynamic load and grid refresh
Post by: Onegin on July 08, 2011, 02:02:30 AM
I actually sorted this out, hopefully it can help someone else:

if you use lazy data load to branches of a treegrid, the URL property will be poluted by queryParams, such as
id = id of selected row
pageNumber = from pagination (if used)
pageSize = from pagination (if used)
this is everything perfectly ok, till you decide to reload the whole grid (e.g. after you append a new row). The poluted data URL is used to fetch data from server, but with appended queryParams the server cannot really distinguish whether to send all recordset or only branch data. For that reason you have to clear things out.

Used this snippet to reload grid:
Code:
var params = $('#tt').treegrid('options').queryParams;
if(params.id){delete params.id};
$('#tt').treegrid('reload');

Note, that I preserved all other params except id, as they will not interfere with server side logic.
also note, that pagination object must be handled separately:

I added this event function:
Code:
onBeforeRefresh:function(pageNumber, pageSize){
            var params = $('#tt').treegrid('options').queryParams;
            if(params.id){delete params.id};
        }

If there is a smarter way how to handle this kind of a problem, I will certainly appreciate to hear about it. Thanks.


Title: Re: treegrid dynamic load and grid refresh
Post by: stworthy on July 12, 2011, 12:21:28 AM
Update to the version 1.2.4 and you can simply call 'reload' method, don't need to delete the 'id' property.