Fix paginator by sorting query