Gantt Selected Task in javascript

1 Answer 20 Views
Gantt
Jerry
Top achievements
Rank 2
Iron
Iron
Jerry asked on 23 Jun 2022, 03:45 PM

I have added a custom button in place of the "Add Task" but can't seem to figure out how I can find the selected task from the gantt chart in javascript.  I am trying to force a popup so that the user can only select from a list of items to add as a task, depending on level they are selecting.  Any samples or ideas would be great.

Thanks!

1 Answer, 1 is accepted

Sort by
0
Accepted
Peter Milchev
Telerik team
answered on 28 Jun 2022, 12:52 PM

Hello Jerry,

For convenience and better visibility from the community, I am sharing the answer from the related support thread:

You can reuse the demo's code to create a custom toolbar button where you can find the selected task and show your custom popup:

Here is a modification of the handler code that accesses the selected task and the level of the task:

<script>
    function findTaskByUid(gantt, uid) {
        for (var i = 0; i < gantt.get_allTasks().length; i++) {
            var task = gantt.get_allTasks()[i];
            if (task._uid == uid) {
                return task;
            }
        }
    }
    function findTaskByID(gantt, id) {
        for (var i = 0; i < gantt.get_allTasks().length; i++) {
            var task = gantt.get_allTasks()[i];
            if (task.get_id() == id) {
                return task;
            }
        }
    }

    function toolbar_click(button, ev) {
        var gantt = $telerik.$(button).closest(".RadGantt")[0].control;
        var tasksInProgressCount = 0;
        var selectedRow = gantt.get_kendoWidget().select();

        var selectedTaskUid = selectedRow.attr("data-uid");
        var task = findTaskByUid(gantt, selectedTaskUid);
        if (task) {
            var level = 0;
            var parentTask;
            while (task.get_parentId()) {
                task = findTaskByID(gantt, task.get_parentId())
                level++;
            }
            alert("task level: " + level)
        }
// show a popup with custom tasks here...return false; } </script>

 

Depending on your implementation, once you select the task from the list, you can directly make a postback and update the database to add the task and set the correct ParentID.

Regards,
Peter Milchev
Progress Telerik

The Premier Dev Conference is back! 

Coming to you live from Progress360 in-person or on your own time, DevReach for all. Register Today.


Tags
Gantt
Asked by
Jerry
Top achievements
Rank 2
Iron
Iron
Answers by
Peter Milchev
Telerik team
Share this question
or