Density is important in a way, but gravity is well understood as an effect of mass.
If Dr Evil shot the Sun with a shrinking ray, so all its mass were compressed until it became a black hole - Earth would still orbit it the same way (same distance) it does now. The density has no effect on how "much" Gravity Earth feels from the Sun. (Especially at this distance, where we can calculate gravitational effects as being from the centre of mass).
The difference would be as you get closer: if the Sun were compressed enough it could become black hole, where it would be possible to get so close you couldn't escape. That even applies to Earth. Right now we can stand - and even jump a little ... because we are far enough away from it's centre of mass. But if the mass of Earth were compressed enough (essentially, by magic, same mass but smaller radius), then standing on the "surface" we'd be squashed by the gravity - even to the point where (again, this would take magic) Earth became a black hole.
This is quite different to digging down into Earth in its current un-compressed state. As we dig down, some of the mass is above us instead of below, so we'd actually feel less and less gravity.