Improvements for ordering in custom exports - code update after QA

This is addition for this PR: https://github.com/dimagi/commcare-hq/pull/4312
I couldn't push this commit directly.

I fixed:
http://manage.dimagi.com/default.asp?137670
http://manage.dimagi.com/default.asp?137681
but I can't reproduce this one, I can locally download or bulk reports:
http://manage.dimagi.com/default.asp?137682