# moveTask

### Description

@short: Moves a task to a new position

@signature: moveTask: (sid: string | number, tindex: number, parent?: string | number) =\> boolean | void

### Parameters

- `sid` - (required) *string | number* -            the id of the task to move
- `tindex` - (required) *number* - the index of the position that the task will be moved to <br/> (the index within a branch)
- `parent`	- (optional) *string | number*		-	the parent id. If specified, the <b>tindex</b> will  refer to the  index in the <br/> <b>'parent'</b> branch

### Returns
- ` result` - (boolean | void) - returns `false` if the action has been canceled using [onBeforeTaskMove](api/event/onbeforetaskmove.md), returns `undefined` otherwise

### Example

~~~jsx
const tasks = {
  data:[
     {id:"p_1", text:"Project #1", start_date:"01-04-2023", duration:18, 
     open:true},
     {id:"t_1", text:"Task #1", start_date:"02-04-2023", duration:8,
     parent:"p_1"},
     {id:"t_2", text:"Task #2", start_date:"11-04-2023", duration:8,
     parent:"p_1"}
   ]
};
gantt.init("gantt_here");
gantt.parse(tasks);
 
gantt.moveTask("t_1", 1); /*!*/
//-> after such a move, the task "t_1" will have the root level
~~~

### Related API
- [getTaskIndex](api/method/gettaskindex.md)
- [onBeforeTaskMove](api/event/onbeforetaskmove.md)
- [onAfterTaskMove](api/event/onaftertaskmove.md)

