Thread Tools Display Modes
03/17/19, 08:53 AM   #1
Deathbat219
Join Date: Mar 2019
Posts: 9
ScrollList not populated with data

Hi.
I'm trying to create a scroll list that will display names of all my characters but I have a problem. The master list is populated with names but the SetupRow function is never called. What should I do to populate my list with data?
Here's my code:
Lua - https://pastebin.com/DBjtkZ9b
Xml - https://pastebin.com/bvs63t1s
  Reply With Quote
03/17/19, 09:55 AM   #2
sirinsidiator
 
sirinsidiator's Avatar
AddOn Author - Click to view addons
Join Date: Apr 2014
Posts: 1,566
You need to define the function FilterScrollList and actually apply your master list to the scroll data.

Lua Code:
  1. function CharacterList:FilterScrollList()
  2.     local scrollData = ZO_ScrollList_GetDataList(self.list)
  3.     ZO_ClearNumericallyIndexedTable(scrollData)
  4.  
  5.     for i = 1, #self.masterList do
  6.         scrollData[#scrollData + 1] = ZO_ScrollList_CreateDataEntry(1, { name = self.masterList[i] })
  7.     end
  8. end

In your case it would be better to change the content of the master list so you do not have to create the data entry all the time, since characters do not change during a session anyways.


Lua Code:
  1. for i = 1, GetNumCharacters() do
  2.         table.insert(self.masterList, ZO_ScrollList_CreateDataEntry(1, { name = zo_strformat("<<1>>", GetCharacterInfo(i)) }))
  3.     end
Then you can just copy the master list:
Lua Code:
  1. function CharacterList:FilterScrollList()
  2.     local scrollData = ZO_ScrollList_GetDataList(self.list)
  3.     ZO_ClearNumericallyIndexedTable(scrollData)
  4.     ZO_ShallowTableCopy(scrollData, self.masterList)
  5. end

In addition you can also overwrite the SortScrollList function to change the sort order of your scroll list.
Lua Code:
  1. function CharacterList:SortScrollList()
  2.     local scrollData = ZO_ScrollList_GetDataList(self.list)
  3.     table.sort(scrollData, myComparisonFunction)
  4. end
  Reply With Quote
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
03/23/19, 07:47 AM   #4
Deathbat219
Join Date: Mar 2019
Posts: 9
Thank you guys for your help. It works perfectly now
  Reply With Quote

ESOUI » Developer Discussions » Lua/XML Help » ScrollList not populated with data

Thread Tools
Display Modes

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