How to scroll a selected task into view?

Hi,

Let’s say I have more tasks than can be displayed onscreen. If I select a task that is off-screen using

gantt.selectTask(id)

how do I automatically scroll it into view?

(I’ve looked at the documentation and the only thing I’ve found related to scrolling is to do it to a x/y position, which isn’t a help without a way of converting the task id to an y position. And I found no hint anywhere on how to do that conversion.)

Thanks,
Fred S

Hello,

You can click on the required task in grid for displaying it on the screen.
Click on the event “Task 3.3” and it will be displayed on the screen:
docs.dhtmlx.com/gantt/samples/03 … onfig.html

Perhaps I wasn’t making myself clear enough. I’m looking for a solution to do it programmatically. Meaning using code. Not user interaction.

Found any solution for this?

Hi @Srdjan_Stajic,
For now, it could be done using the getTaskPosition method, which provides the functionality, to find the task’s position on the chart. After that you will be able to move to this position using the scrollTo method, it may look like in this code fragment:

var task = gantt.getTask(id);
var sizes = gantt.getTaskPosition(task, task.planned_start, task.planned_end);
gantt.scrollTo(sizes.left, sizes.top);

Here is a demo:
http://snippet.dhtmlx.com/ae38755c2

API:
scrollTo:
https://docs.dhtmlx.com/gantt/api__gantt_scrollto.html
getTaskPosition:
https://docs.dhtmlx.com/gantt/api__gantt_gettaskposition.html