I am working on a SilverStripe project. In my project, I am adding components to the GridField dynamically. Actually, I am trying to replace the existing components. Since there is no replace method, I have to remove the existing components and add the new components.
Following is my code
$grid = new GridField('ContentBlocks', 'Content Blocks', $this->owner->ContentBlocks(), $editor);
$grid->getConfig()
->removeComponentsByType(GridFieldAddExistingAutocompleter::class)
->addComponent(new CustomGridFieldAddExistingAutocompleter())
//configuring other components continue here
As you can see in my code, I am removing an existing component and adding a new custom component as a replacement for the one that was removed.
It added the custom component. But there is an issue with that. The issue is that on the front-end, the new component is not added at the exact position as the one that was removed.
See this screenshot:
As you can see in the screenshot, the search box (the custom component added) went out of the container or div that the add content block button resides in. If I did not do that replacement, they stay in the same row as in the screenshot below.
What I am thinking is that I am looking for a way to group them back together in one row. How can I do that? Is it possible?