Thread: Trying to Learn
View Single Post
06-29-19, 09:39 AM   #26
fusionpit
A Murloc Raider
AddOn Author - Click to view addons
Join Date: Apr 2009
Posts: 6
Originally Posted by Aeriez View Post
Is FauxScrollFrame capable of, say, a 3-4 column sheet (ie: Listing players, their class, their dkp etc) that is sortable by each column?
Absolutely it is. The auction house uses a ScrollFrame based on FauxScrollFrameTemplate to implement the browse portion, which can also be sorted by the column tabs at top.

Here is the template blizz uses for the AH sort tabs, here is an example of how that template is used in xml, and here is the sorting being done in lua.

For your case you would need to store some state like the direction of the sort, but that would be pretty simple. You could use table.sort to reorder the source of the FSF, with the sort func being tied to the column and direction. After that you just run your Update function to repopulate the FSF with the newly ordered data.

Lua Code:
  1. local data = {
  2.     {player="Sveng",class="Mage",dkp=1.41},
  3.     {player="Sarex",class="Rogue",dkp=-50}
  4. };
  5. function MyFrame_Update()
  6.     local offset = FauxScrollFrame_GetOffset(MyScrollFrame);
  7.     for i=1,MAX_ROWS do
  8.         local row = _G["MyScrollFrameRow"..i];
  9.         local rowData = data[i+offset];
  10.         if (rowData ~= nil) then
  11.             -- set row data
  12.             row:Show();
  13.         else
  14.             row:Hide();
  15.         end
  16.     end
  17.     FauxScrollFrame_Update(MyScrollFrame, #data, MAX_ROWS, ROW_HEIGHT);
  18. end
  19. ...
  20. -- 'true' being asc, 'false' being desc, 'nil' being unsorted
  21. local sortDirections = {player=nil,class=nil,dkp=nil};
  22. local function sortData(propKey, direction)
  23.     sortDirections[propKey] = direction == "asc"
  24.     table.sort(data, function(a,b)
  25.         if (a[propKey] == b[propKey]) then
  26.             return nil;
  27.         end
  28.         if (sortDirections[propKey]) then
  29.             return a[propKey] < b[propKey];
  30.         else
  31.             return a[propKey] > b[propKey];
  32.         end
  33.     end);
  34.     FauxScrollFrame_SetOffset(MyScrollFrame, 0);
  35.     MyFrame_Update();
  36. end
  37. sortData("dkp", "desc");
  Reply With Quote