Greetings,
I have smart rendering enabled, Is there a way to find the list of tasks that are currently visible in the view?
Lets say I have 18 tasks currently rendered based on my screen real estate. I want to find the id of the last task and then scroll to task 19 at the top.
My current solution:
- $(".gantt_bars_area > div:last").attr("task_id") - will give me the last task id, use that to find the next_task_id.
- gantt.scrollTo(null, gantt.getTaskTop(next_task_id)) - To render to the next screen from top.
Is there is a cleaner way of doing this with the api?
Hello,
Although there is no special function to get all tasks displayed on the screen, it is possible to get it via API. Please check the following snippet to see how it can be implemented: snippet.dhtmlx.com/6ea67e88a
gantt.getTaskRowNode is used to show the HTML element of the row. If it is not visible the function returns null. So we get all visible tasks IDs in an array. Then we just scroll down to the latest visible task.
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.
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);
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.
Hello Joseph,
Thank you for pointing that. I forgot to check how it works for the initial state, when one of the invisible rows at the beginning, not at the end. Here is the updated snippet: http://snippet.dhtmlx.com/117ba1101
Get a guaranteed answer from DHTMLX technical support team
under the most suitable support plan