Thread Tools Display Modes
07/24/15, 07:16 PM   #1
kerb9729
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 57
Next project

I think for my next project, I am going to make it so that group members appear first in my ZO_Scrolllist.
It seems like I should be able to do that by modifying the sort list keys.

My idea is that I add a group membership column to my listdata (though that column of the table won't be displayed displayed as a column in the scrolllist.) I think i should be able to add it to my sort keys. Then I'm hoping I can sort on group members first and then sort on name or zone, whichever of those headers were clicked.

Am I nuts? Or does this sound feasible?

Although, I'm not sure that's the best way to go. Perhaps I should just create a 2nd scrolllist?
Kinda on the fence about which would be proper.
  Reply With Quote
07/24/15, 08:23 PM   #2
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Should be feasible by just overriding the comparison function. I'll leave isInGroup implementation to yourself

Lua Code:
  1. local function overrideSortFunction(self, sortKeys)
  2.     function self.sortFunction(listEntry1, listEntry2)
  3.         local data1 = listEntry1.data
  4.         local data2 = listEntry2.data
  5.         if isInGroup(data1) then
  6.             if not isInGroup(data2) then
  7.                 return true -- 1 (group member) comes before 2 (non-member)
  8.             end
  9.         else
  10.             if isInGroup(data2) then
  11.                 return false -- 1 (non-member) comes after 2 (group member)
  12.             end
  13.         end
  14.         -- both members or both non-members, break the tie using the usual column sorting rules
  15.         return ZO_TableOrderingFunction(data1, data2, self.currentSortKey, sortKeys, self.currentSortOrder)
  16.     end
  17.     self:RefreshSort()
  18. end
  19.  
  20. overrideSortFunction(GUILD_ROSTER_KEYBOARD, GUILD_ROSTER_ENTRY_SORT_KEYS)
  21. overrideSortFunction(FRIENDS_LIST, FRIENDS_LIST_ENTRY_SORT_KEYS)

Last edited by merlight : 07/24/15 at 08:25 PM.
  Reply With Quote
07/25/15, 02:00 PM   #3
kerb9729
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 57
Originally Posted by merlight View Post
Should be feasible by just overriding the comparison function. I'll leave isInGroup implementation to yourself

Lua Code:
  1. local function overrideSortFunction(self, sortKeys)
  2.     function self.sortFunction(listEntry1, listEntry2)
  3.         local data1 = listEntry1.data
  4.         local data2 = listEntry2.data
  5.         if isInGroup(data1) then
  6.             if not isInGroup(data2) then
  7.                 return true -- 1 (group member) comes before 2 (non-member)
  8.             end
  9.         else
  10.             if isInGroup(data2) then
  11.                 return false -- 1 (non-member) comes after 2 (group member)
  12.             end
  13.         end
  14.         -- both members or both non-members, break the tie using the usual column sorting rules
  15.         return ZO_TableOrderingFunction(data1, data2, self.currentSortKey, sortKeys, self.currentSortOrder)
  16.     end
  17.     self:RefreshSort()
  18. end
  19.  
  20. overrideSortFunction(GUILD_ROSTER_KEYBOARD, GUILD_ROSTER_ENTRY_SORT_KEYS)
  21. overrideSortFunction(FRIENDS_LIST, FRIENDS_LIST_ENTRY_SORT_KEYS)
Oh I like this method much better than my idea. This doesn't require adding anything to the table.
  Reply With Quote
07/26/15, 12:31 AM   #4
kerb9729
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 57
Your code was to sort groupmembers first in the friend and guild roster, right?
But that wasn't exactly what I wanted. I needed them sorted first in my own little scrolllist.

Thanks to your help I was able to modify the sort function for the SortHeader group:

Lua Code:
  1. GOTO_PANE.sortHeaders = ZO_SortHeaderGroup:New(GOTO_PANE:GetNamedChild("Headers"), SHOW_ARROWS)
  2.     GOTO_PANE.sortHeaders:RegisterCallback(ZO_SortHeaderGroup.HEADER_CLICKED,
  3.         function(key, order)
  4.             table.sort(
  5.                 ZO_ScrollList_GetDataList(GOTO_PANE.ScrollList),
  6.                 function(entry1, entry2)
  7.                     if isInGroup(entry1.data.playerName) then
  8.                         if not isInGroup(entry2.data.playerName) then
  9.                             return true -- 1 (group member) comes before 2 (non-member)
  10.                         end
  11.                     else
  12.                         if isInGroup(entry2.data.playerName) then
  13.                             return false -- 1 (non-member) comes after 2 (group member)
  14.                         end
  15.                     end
  16.                     -- both members or both non-members, break the tie using the usual column sorting rules
  17.                     return ZO_TableOrderingFunction(entry1.data, entry2.data, key, GOTO_SCROLLLIST_SORT_KEYS, order)
  18.                 end)
  19.             ZO_ScrollList_Commit(GOTO_PANE.ScrollList)
  20.         end)
  21.     GOTO_PANE.sortHeaders:AddHeadersFromContainer()

I found that the default sort value set in ZO_SortHeader_Initialize did not seem to be applied (initally, the table displayed unsorted.) Here is the init call:
ZO_SortHeader_Initialize(GOTO_PANE.Headers.Name, "Name", "playerName", ZO_SORT_ORDER_UP, TEXT_ALIGN_LEFT, "ZoFontGameLargeBold")

A call to GOTO_PANE.sortHeaders:SelectHeaderByKey("playerName") after I populate the data seems to resolve that issue, but I wonder if I made an error in Sortheader_Initialize, or if there's a bug.
  Reply With Quote
07/26/15, 04:04 AM   #5
merlight
AddOn Author - Click to view addons
Join Date: Jul 2014
Posts: 671
Originally Posted by kerb9729 View Post
I found that the default sort value set in ZO_SortHeader_Initialize did not seem to be applied (initally, the table displayed unsorted.) Here is the init call:
ZO_SortHeader_Initialize(GOTO_PANE.Headers.Name, "Name", "playerName", ZO_SORT_ORDER_UP, TEXT_ALIGN_LEFT, "ZoFontGameLargeBold")

A call to GOTO_PANE.sortHeaders:SelectHeaderByKey("playerName") after I populate the data seems to resolve that issue, but I wonder if I made an error in Sortheader_Initialize, or if there's a bug.
That's intended. ZO_SortHeader_Initialize(...) intializes the given header, if you had 5 column headers you'd call ZO_SortHeader_Initialize(...) for each of them, setting up their sort key name and default sort direction.

The call to SelectHeader/SelectHeaderByKey sets which of those headers is "active" (decides ordering).
  Reply With Quote
07/26/15, 09:44 AM   #6
kerb9729
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 57
Originally Posted by merlight View Post
That's intended. ZO_SortHeader_Initialize(...) intializes the given header, if you had 5 column headers you'd call ZO_SortHeader_Initialize(...) for each of them, setting up their sort key name and default sort direction.

The call to SelectHeader/SelectHeaderByKey sets which of those headers is "active" (decides ordering).
That makes perfect sense. Thanks for the explanation!
  Reply With Quote

ESOUI » Developer Discussions » General Authoring Discussion » Next project


Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off