How to clear a layout cell before .attach?

I have a layout object with a toolbar cell and a main content cell, say I’m displaying a grid and I want instead to display a treeview when the toolbar is clicked, adding it is easy:

mainCell.attach(treeviewObject)

But how do I clear the mainCell before using .attach or is this not necessary?

You don’t need to clear Layout cell before attaching another component, just call attach() method once again.
See this snippet.

Ok thanks. One more question - is it possible to to use layoutcell.attach for the gantt component?
All the code I have seen uses gant.init(“divid”) but I want to attach grid/gantt/treeview into the cell using the method you describe.

Unfortunaetly it is not available to use teh attach() method to attach a gantt object to the layout cell.

You may use the attachHTML() to attach a dive container to a layout cell and attach a gantt to that container, or you may try to use the following workaround:
https://snippet.dhtmlx.com/ttampo9h
attaching a gantt object durecrtly to the layout cell