I stumbled upon it when trying to set a default sorting for my add-on.
The bug is: 'OnHeaderClicked' is ignoring the initial direction given by ZO_SortHeader_Initialize.
Let's take a look:
File esoui\libraries\zo_sortheadergroup\zo_sortheadergroup.lua, from line 149 to 165
Lua Code:
function ZO_SortHeaderGroup:OnHeaderClicked(header, suppressCallbacks, forceReselect)
if self:IsEnabled() then
local resetSortDir = false
if forceReselect or not self:IsCurrentSelectedHeader(header) then
self:DeselectHeader()
resetSortDir = true
end
self.sortDirection = resetSortDir and header.initialDirection or not self.sortDirection
self:SelectHeader(header)
if(not suppressCallbacks) then
self:FireCallbacks(self.HEADER_CLICKED, header.key, self.sortDirection)
end
end
end
Upon first calling 'OnHeaderClicked' (whether by clicking on the header or calling 'SelectHeaderByKey'), the line that sets 'sortDirection' always gets true, no matter what. I think the problem is the use of 'x and y or z', since sortDirection is a boolean flag, it's tricky to use this ternary-ish conditional instead of a full body if/else.
Edit.
Yes! As I suspected, changing the line
Lua Code:
self.sortDirection = resetSortDir and header.initialDirection or not self.sortDirection
to
Lua Code:
if resetSortDir then
self.sortDirection = header.initialDirection
else
self.sortDirection = not self.sortDirection
end
Fixed the problem!
I always found 'x and y or z' smelly, a mine waiting to be detonated. :P