[fixed] Faulty code in ZO_SortHeaderGroup:OnHeaderClicked
There is a problem in the ZO_SortHeaderGroup:OnHeaderClicked function (found in \esoui\libraries\zo_sortheadergroup\zo_sortheadergroup.lua), specifically, with the following line of code:
self.sortDirection = resetSortDir and header.initialDirection or not self.sortDirection
The "condition and a or b" shorthand in Lua is subject to one crucial caveat: the "a" term must never be nil or false. If it is, then "b" will always be used, regardless of what "condition" evaluates to.
In this case, since the sort directions are stored as either true or false, this line of code returns the incorrect result if resetSortDir is true and initialDirection is down (false). This code must be replaced with if-then longhand (reversing the condition and swapping a and b will suffer the same problem).
You can see this bug in action if you try to use SelectAndResetSortForKey on a column that has a downward initial sort direction.
(Also, it might be a good idea to audit the code for more instances of these "condition and a or b" shorthands--this is a subtle and easily-missed error, and there could be other places that might have similar problems.)