Start Building Professional
Web Apps Today


 
Categories Question details Back To List
Question  posted by Vikrant on Nov 29, 2008 02:31
open dhtmlx forum
change position of child row in a treegrid

Hi,

How we can change the row position of child row in a treegrid.
I have written two function at dhtmlxgrid.js
that takes the child row to the top and bottom of his relevant parent
this.moveRowTop=function(row_id){
         var r = this.getRowById(row_id);
         var childpos = this.rowsCol._dhx_find(r);
         var childparentid=this.getParentId(r.idd);
         var pr = this.getRowById(childparentid);
         var parentpos = this.rowsCol._dhx_find(pr);
         var no=parentpos+1-childpos ;
        return this.moveRowUDTG(row_id, no);
    }
this.moveRowBottom=function(row_id){
         var r = this.getRowById(row_id);
         var childpos = this.rowsCol._dhx_find(r);
         var childparentid=this.getParentId(r.idd);
         var pr = this.getRowById(childparentid);
         var parentpos = this.rowsCol._dhx_find(pr);
         var noofchild=this.hasChildren(childparentid);
         var no=parentpos+noofchild-childpos ;
         this.moveRowUDTG(row_id, no);
}
    
But it is not working. please provide me some sample code for this. I have to do a child fc on the top or bottom of its relevant parent depending on situation.

Its very urgent for our product.
Answer posted by Support on Dec 01, 2008 01:51
You can use

as last child
    grid.moveRowTo(rowId, targetId, "move", "child");

as first child
    grid.setDragBehavior("sibling-next");
    grid.moveRowTo(rowId, targetId, "move", "sibling");
Answer posted by Vikrant on Dec 01, 2008 02:58

Hi,

I have written  the code below but it doesnot work in case of move up. In that case we need to change the order of a row so the rowis and target id is same. Please help me. 

mygrid.moveRowTo(rowid, rowid, "move", "sibling");

 

Answer posted by Vikrant on Dec 01, 2008 03:10

Hi,

I am also facing the same problem. The simple form of my situation:
The grid has only one parent.
Under this parent there are 5 children i.e Total of 6 rows - 1 parent and 5 children
I am writting a button on click of which, the selected row should become the first child.

PARENT ROW
    CHILD #1
    CHILD #2
    CHILD #3
    CHILD #4
    CHILD #5

If I select row "CHILD #3" and then click the button, the grid should change to:
PARENT ROW
    CHILD #3
    CHILD #1
    CHILD #2
    CHILD #4
    CHILD #5

In the above similar fashion, I'm creating button to move selected row to the bottom i.e the result would become:
PARENT ROW
    CHILD #1
    CHILD #2
    CHILD #4
    CHILD #5
    CHILD #3

Note: my grid implementation is WITHOUT dragndrop support. (with my implementation, user should not be allowed to do dragndrop of rows)

Thanks.

 

Answer posted by Support on Dec 01, 2008 03:15
Working sample sent by email.