View Single Post
03/20/19, 04:19 PM   #3
Drummerx04
AddOn Author - Click to view addons
Join Date: Sep 2017
Posts: 54
Post

The "masterList" table is not actually the active list of elements that go into the list displayed to the user.

It's also worth mentioning that the tutorials on the scroll list (and ZO_libraries in general) are horrendous, and do very little to explain how they are intended to be used, so I will try to give a little info here.

Lua Code:
  1. CharacterList = ZO_SortFilterList:Subclass()

After Subclass() is called, CharacterList is essentially an instance of ZO_SortFilterList and inherits all functions defined by it. If you only ever intend to use this list for one single display, you don't really need the "New()" function which implies that you will be creating multiple instances of the "class"

The Initialize() function is still used to setup your CharacterList table with all information unique to it's purpose.

Lua Code:
  1. --The main thing this does that you are interested in is that it assigns self.list to be the "List" control
  2. --that you defined in your XML
  3. ZO_SortFilterList.Initialize(self, listControl)

There are several functions meant to be overwritten by you and are called by different ZO_SortFilterList functions (the numbers in the comments are important reference later).
Lua Code:
  1. -- (1)Meant to generate a raw list of elements of interest. In your case, the list of characters
  2. CharacterList:BuildMasterList()
  3. -- (2)Meant to reduce the masterList in some custom way
  4. CharacterList:FilterScrollList()
  5. -- (3)Meant to Sort the list as needed
  6. CharacterList:SortScrollList()
  7.  
  8. --(4)There is also a 4th function that you typically do not call directly, and you do not overwrite it, but knowing it exists is helpful. This function actually renders the elements the list control has been handed.
  9. CharacterList:CommitScrollList()

In one of the 3 mentioned functions you need to add elements to the List control as described by sirinsidiator.

Lua Code:
  1. -- scrollData is the actual table that is stored in your XML defined List control.
  2. local scrollData = ZO_ScrollList_GetDataList(self.list) -- self.list == "MainWindowList" from your xml.
  3. ZO_ClearNumericallyIndexedTable(scrollData) -- This line clears the display list.
  4.  
  5. -- Now just add elements to scrollData as you see fit the main thing is to only add elements created by
  6. local element = ZO_ScrollList_CreateDataEntry(RegisteredIndex, TableYouWantDisplayed)

Now that you've defined the above functions to add/filter/sort elements of your list, you'll want to call one of the inherited functions from ZO_SortFilterList (numbers referenced above)
Lua Code:
  1. CharacterList:RefreshData() -- Calls 1 -> 2 -> 3 -> 4
  2. CharacterList:RefreshFilters() -- Calls 2 -> 3 -> 4
  3. CharacterList:RefreshSort() -- Calls 3 -> 4

So a single call to RefreshData() should render your list at this point.
  Reply With Quote