Order of the row in treegrid

Hi,

I am using Dhtmltreegrid control to display the activities of project. It is working fine but I have a problem while adding an activity between two activities. The row is add but the order is not proper. For ex:
Activity 1
Activity 2
Activity 3
Activity 4

When I add Activity x in between Activity 2 & 3 the Activty X is coming at the end not between 2 & 3.
Can you please help us with some sample code?

Which method you are using for row adding. Treegrid has two additional commands which can be used for placing new row at specific position

grid.addRowBefore(newid, text, siblingid);
grid.addRowAfter(newid, text, siblingid);

where siblingid - id of row before, or after each new one must be added

Thanks for information Stanislav

function addBefore(){
var sel=mygrid.getSelectedId();
if (!sel) return;
var rowId1 = mygrid.uid();
mygrid.addRowAfter(rowId1,[0,“New”],sel);
}

I am using this function to add a new row. When I insert the row it is displaying as if it is inserted at the exact location. But we retrive the back from the database it is moving to last to row.

Activity 1
Activity 2
Activity X
Activity 3
Activity 4

after retrive from database
Activity 1
Activity 2
Activity 3
Activity 4
Activity X

Beware, that if you are using connectors for DB operations, they doesn’t save row indexes by default.