Hello friend, fascinating question posted by you. Simple answer is yes. A magnetic field of a magnet is merely created by the in built arrangement of the electrons in a particular end to end alignment. Thus all the negative charges accumulate along one direction and all the opposite charges accumulate in the opposite direction. This kind of alignment has nothing to with the gravitational force that the magnet experiences from its surrounding bodies or that of the Earth. So wherever the magnet is, either inside the earth's gravitational field or in the outer space, the magnetic field created by the magnet is same. This means that the magnet attracts and repels the unlike and like poles from other magnets respectively. If a ferromagnetic substance is taken to outer space and place in the near field of the magnet, the substance gets attracted toward the magnet.
However, when you want to see the functionality of a magnetic compass, and expect it show directions, that depends on how far from the earth you are. If the compass is within the distance equal to the one-fourth distance to moon from earth, then the compass works. After that distance, the magnetic field from the earth, the sun and other planets is negligible to rotate the compass needle.
I hope you got clarified. If not feel free to ask again.