Hello Joseph,
We don’t have an API command that will return all tasks that are visible on the screen.
But you can use the following commands to get visible task IDs by using DOM properties (that should be faster than checking all tasks):
var data = gantt.$grid_data.childNodes;
var ids = [];
for (var i = 1; i < data.length; i++) {
ids.push(data[i].attributes.task_id.nodeValue)
}
console.log(ids);
Here is the snippet:
http://snippet.dhtmlx.com/c8b542f25
Another way to do that is to get the Gantt container parameters, calculate the number of visible tasks and get tasks by their index.:
var tasks = [];
var first_visible_id = Math.floor(gantt.getScrollState().y / gantt.config.row_height)
var visible_rows = Math.floor(gantt.$container.clientHeight / gantt.config.row_height);
for (var i = 0; i < visible_rows; i++) {
tasks.push(gantt.getTaskByIndex([first_visible_id + i]))
}
console.log(tasks);
Here is the snippet:
http://snippet.dhtmlx.com/f6aa10b72
If you look inside the method in web inspector , it’s simply returnsthis._order.length.
Now in the console, if you print gantt._order, it will return you an array of the ids.
It is not recommended to use the internal API methods as they might change and we won’t warn about that. If the public API method is deprecated, you are warned about that and have time to replace the commands.