There is no default functionallity for this.
If the solution with the dataview listening to the grid doesn’t work (for instance whenn you need multi select or be able to click the button when you dit not select a row), the easiest way to solve this is to move the datagrid button in CSS to the (fixed) place where you need it.
If the CSS option is not possible, you can add a custom on-click nanoflow that toggles the selection on the clicked row (with an extra boolean field at the entity, or an extra non-persistent entity to mark your selection). With the microflow behind the button outside the datagrid you can retrieve your selected row(s) and perform the desired action. Make sure you reset your selection when you enter the page!
Usually I’ll use a listview instead of a datagrid because you have more options for layout and extra controls. But the above is also possible with a datagrid.
Add a dataview that listens to the datagrid. In that dataview you can add your button. You can even do something with the visibility when $currentobject != empty…