Maybe use a listen to construction. Add a dataview for the object in the list that listens to the grid and use the visibility expression to only show the dataview when the currentobject != empty. With some additional styling to ensure that space is not used when the dataview is not shown.
Or this component can help out: https://marketplace.mendix.com/link/component/202578 not sure if it is compatible with your verion of Mendix though.