Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Lubos on Dec 01, 2008 02:30
open dhtmlx forum
setting initial page number for loading for dhtmlxgrid component

Hello,
I have problem loading custom page in dhtmlxgrid component.
Here is the scenario: user configures that she wants to see page 2 when she goes to a page with grid.
Is there a way, how to do this programmatically? (set initial page for loading)?
Moreover we need the requests to be done using POST and always (clear the cache of dhtmlxgrid)

We've found this way:

function onXleFunc(grid,count) {
    data = mygrid.getStateOfView();
    for (var i = data[1]; i<data[2]; i++) //for rows on current page
        mygrid.rowsBuffer[i]=null;
    return false;
}
...
mygrid.attachEvent("onXLE",onXleFunc);
...
gridQString = 'http://localhost:8080/xxx/data/data?'+searchUrlParams;
mygrid.loadXML(gridQString, function() { mygrid.changePage(somePage); });

This has several drawbacks:
1. there are always two downloads (always!)
2. the downloads of XML are made by "get", not "post" HTTP methods, which we prefer
Answer posted by Support on Dec 01, 2008 02:58
>>1. there are always two downloads (always!)
Yes, this is known side-effect of above scenario. 
Can be resolved as 

grid.attachEvent("onDynXLS",function(pos,start){
            if (pos==0 && somePage!=1) return false; // block second call
            return true;
});
mygrid.loadXML(gridQString, function() { mygrid.changePage(somePage); });

>>2. the downloads of XML are made by "get", not "post" HTTP methods, which we prefer
You can use additional extension and postXML instead of loadXML
               http://dhtmlx.com/docs/products/kb/index.shtml?cat=search&page=1&q=6617&ssr=yes&s=post%20paging

Answer posted by Lubos on Dec 01, 2008 04:12

Unfortunately this code doesn't work. The problem is that with the first call to server (with no setting of posStart and count parameters), the onDynXLS event is never called!

Do you have any idea, how to hack the code to force htmlxgrid to not call the first call without the startPos and count paramters?

Answer posted by Support on Dec 01, 2008 08:07
>>the onDynXLS event is never called!
This is expected , onDynXLS will be called only for automatic data loading calls, and not for the ones initiated directly. 

With the same code as above, you can have 

var gridQString = "grid.php?pos="+somePage*pageSize+"&count="+pageSize;

In such case , first call will requiest and load data for required page, after which grid will generate second ( unwanted ) data call , which will trigger onDynXLS event, and will be blocked.