dhtmlXGrid - server side sorting sub grid

I have a page in which I am trying to sort a sub grid. Sorting on the parent grid works just fine. When I try to sort on the sub grid however, it will sort (ASC) the first time I click the header, but the sorting arrow appears and disappears right away, while keeping in the correct sorted state(ASC). Then when I click on the header to sort (DESC) it the second time, it seems to sort(DESC) it correctly, but the sort arrow appears and disappears very quickly, and then reverts back to the previous sort state(ASC).



The weird thing is that if I insert an alert() statement in front of the function this.setSortImgState(true,ind,direct); and then click on ok in the dialog box that it creates, the sub grid sorts just fine! Any help would be great! Thank you!



function doInitRegionalMinstrySubGrid(subGridObj,rowId,rowIndex) {

subGridObj.enableSmartRendering(true);



subGridObj.attachEvent(“onBeforeSorting”,function(ind,type,direct){

                var subGridQString = “regionalXML.php”;

                

                this.clearAll(); // clear grid

                this.loadXML(subGridQString+(subGridQString.indexOf("?")>=0?"&":"?")+“orderby=”+ind+"&direct="+direct);

                this.setSortImgState(true,ind,direct); //set a correct sorting image            

                

                return false;

            });

            

subGridObj.loadXML(‘regionalXML.php’,function(){

            subGridObj.callEvent(“onGridReconstructed”,[]); //will correct sub-grid size after data loaded in it

            });             

}



Try to change it as

subGridObj.attachEvent(“onBeforeSorting”,function(ind,type,direct){
var subGridQString = “regionalXML.php”;

this.clearAll(); // clear grid
this.loadXML(subGridQString+(subGridQString.indexOf("?")>=0?"&":"?")+“orderby=”+ind+"&direct="+direct,function(){
this.setSortImgState(true,ind,direct); //set a correct sorting image
});

return false;
});

The row sorting state can be reset by incoming XML ( it it contains head section and in some other cases ), but if you will use after call to set sorting state - it will be set after data loading and must not be corrupted.