How to close and open branches programmatically in ui.gantt?

How can I close and open branches programmatically in ui.gantt? For opening or closing all branches I tried this simple approach.

$$("my-gantt").queryView("treetable").openAll();

and

$$("my-gantt").queryView("treetable").closeAll();

While the branches are opened and closed in the treeview of the ui.gantt as expected the barsview is not updated. How to do this the right way?

Regards
Markus

Good day @Markus-P ,

Please, check the example: Code Snippet .

The default logic is placed in the gantt.views.tree - in the onAfterOpen()/onAfterClose() events handlers of the treetable.

For opening single branches programmatically you could use treetable.open(id)/close(id) methods as will call the original logic (after these methods onAfterOpen()/onAfterClose() events in a gantt.views.tree will fire).

However, treetable openAll()/closeAll methods are working in a different way and does not call onAfterOpen() event so we could call the separate function and try repeating the same as done in these events.
The toggleAllBranches function in the example will visually open/close all the branches on the buttons click.

Thanks for your solution, which works very well!

I have a similiar problem regarding filtering the underlying treetable of a gantt.

I tried to apply your solution from above, but for some reasons that did not work. In this example only project bars should be shown. But again there is no visible effect.

var gantt = $$("my-gantt");
var tt = gantt.queryView("treetable");
const local = gantt.getService("local");
const tree = local.getVisibleTasksCollection();

tt.filter((obj) => {
	console.log(obj);
	return obj.type == "project";
});

tree.data.callEvent("onStoreUpdated", []);

How can I filter the gantt data?

Kind regards,
Markus

Hello,

After the loading the tasks data is stored in the local data service so you could filter the tasks by directly referencing the tasks() collection from the Local service (in the previous example we also got the tasks collection by local.getVisibleTasksCollection()).
Check the example: Code Snippet .