Table sorting implementation