DHTMLTreeGrid sorting issue

I have a 1 column TreeGrid I am using. I know I could use a Tree right now but I plan to add more column in the near future. So the problem is, I can’t seem to sort the TreeGrid after I build it using setColSorting(str). When I click on the header, it will sort, but I need it to sort itself. ANy ideas on why it is not sorting when I use .setColSorting(str)? I have pasted in 2 snippets below: Thanks in advance.



Stevo



init code on page load:

//load all products in TreeGrid

    mygrid = new dhtmlXGridObject(‘treegridbox’);

    mygrid.setHeader(“Products”);

    mygrid.setInitWidths("*");

    mygrid.imgURL = “images/”;

    mygrid.setColAlign(“left”)

    mygrid.setColTypes(“tree”);

mygrid.enableLightMouseNavigation(false);    

mygrid.attachEvent(“onRowSelect”, “OnProductDblClicked”);

mygrid.setDragHandler(OnGridListDrop);



mygrid.setColSorting(“str”);

mygrid.enableDragAndDrop(true);

    mygrid.enableMercyDrag(true);

    mygrid.enableMultiselect(true);

mygrid.enableSmartXMLParsing(true);

mygrid.setSkin(“sbdark”);

mygrid.setEditable(false);

mygrid.setNoRecordsString(“There are no products selected for this list.”);

    mygrid.init();

    allProdsGridXML = executeTx(urlProds);

     mygrid.loadXMLString(allProdsGridXML); //txPLS.aspx?op=get&tx=lists







**************************************************************************************

rebuilding treegrid code:



mygrid.clearAll(); //clear out out data, start from scratch



if (rowId == -1)

{

mygrid.enableDragAndDrop(true);

if (allProdsGridXML.length > 1)

mygrid.loadXMLString(allProdsGridXML);

else

{

     allProdsGridXML = executeTx(urlProds);

     mygrid.loadXMLString(allProdsGridXML);

}



}

else

{

mygrid.enableDragAndDrop(false);

var temp = mylistsgrid.getSubItems(rowId);

if (temp.length > 0)

{

mygrid.enableMultiselect(true);

var ids=temp.split(",");

for (var i=0; i<ids.length; i++)

{

mylistsgrid.moveRowTo(ids[i],0,“copy”,“child”,mylistsgrid,mygrid); //copying rows from one grid to the one I am building

}



mygrid.collapseAll();

mygrid.setColSorting(“str”);

The next command
    mygrid.setColSorting(“str”);
will just set default sorting type for the first column ( it enables sorting by clicking on grid header )
If you need to force sorting for column programatically - you can use next code
    grid.sortRows(0,“str”,“asc”);   // sort first column, as strings, in ascendant order