Fix ability to sort by case owner

http://manage.dimagi.com/default.asp?121159

best reviewed commit by commit.
@snopoke curious whether the copy-pasted code differs importantly between files, otherwise seems like we could and should just have a single template for this