In the debug inspector I can activate a grid. how can I create / activate the same via code?
If you mean the render grid:
The grid in the inspector creates a ground mesh and sets its material to a GridMaterial. See Grid - Babylon.js Documentation.
But can you toggle this option over the inspector in the code? I think this would be a neat feature.