Proper way to find root task?

Hi,

Sorry if I have missed something obvious, but after consulting the API documentation I just can’t seem to find the proper way to find the root task. (I’ve found the property root_id, but I’m not seeing how that can be the answer to my question.)

Using my data I could do a gantt.eachTask and just pick the task with a parent id of 0, but that doesn’t seem very elegant so I’m thinking I probably have missed something somewhere.

All help appreciated, thanks.
Fred S

There is no public API for this use-case unfortunately. You can iterate through all task by means of eachTask, or get any task object and read it parent property recursively.

If you don’t mind to use the private properties ( not recommended due to long term compatibility with future updates ) you can use

var root = gantt._branches[0];

Thank you very much, that will work nicely for now.

I would also like to request that an official method is added to the API for this. (I imagine it’s really simple for you to do, basically wrapping gantt._branches[0] and returning it’s contents.)

Thanks,
Fred S

Yep, I just have add this feature to the list for the next update.